Python 3.5 tkinter: resizing widgets to window -


i reading, reading , reading still unable find appropriate answer issue. plan create 'masterwindow' in implement several frames (currently navigation panel left, 'rootframe', shows up, when no process running, statusbar @ bottom, alerts , processings , main frame. running code below, works fine, frames not adjust resize of window.

now, know, need sticking in main- , subclasses , set grid_column- , rowconfigure weight of >0 still nothing happens.

i cannot see reason why. missing? need put in masterframe?? stick masterwindow? can't right since inheriting frames everywhere...

thanks effort , input. rgds

p.s: oh way: can any1 tell me how iterate through rows in grid method can 'grid widget in next row' (relative) , dont have use absolute integers?

    # -*- coding: utf-8 -*-      import tkinter.ttk     tkinter import *       class mainapplication(tkinter.frame):         @classmethod         def main(cls):             root = tkinter.tk()             app = cls(root)             app.master.title('sample')             root.resizable(true, true)             root.mainloop()          def __init__(self, parent=none, *args, **kwargs):             tkinter.frame.__init__(self, parent, *args, **kwargs)             self.grid(sticky=n+e+s+w)              # var-declaration             self.h = 600             self.w = 1200             self.widget_fr_opts = dict(relief='groove', borderwidth=1, bg='#efeffb')              #  widget-creation             self.rootframe = rootframe(self)             self._visible_ = self.rootframe  # internal updater frame visible - starting rootframe on init             self.statusbar = statusbar(self)             self.navbar = navbar(self)             self.main_db = maindb(self)              #  widget-design              # widget-arrangement             self.grid_rowconfigure(0, minsize=self.h * 0.95)             self.grid_rowconfigure(1, minsize=self.h * 0.05)             self.grid_columnconfigure(0, minsize=self.w*0.15)             self.grid_columnconfigure(1, minsize=self.w*0.85)             self.navbar.grid(sticky=n+s+e+w, column=0, row=0)             self.main_db.grid(sticky=n+e+s+w, column=1, row=0)             self.rootframe.grid(sticky=n+e+s+w, column=1, row=0)             self.statusbar.grid(sticky=w+e, column=0, columnspan=2, row=1)              self.grid_columnconfigure(1, weight=1)             self.statusbar.columnconfigure(0, weight=1)             self.rootframe.columnconfigure(0, weight=1)             self.main_db.columnconfigure(0, weight=1)              self.grid_rowconfigure(0, weight=1)             self.navbar.rowconfigure(4, weight=1)             self.rootframe.rowconfigure(0, weight=1)             self.main_db.rowconfigure(0, weight=1)              self.rootframe.lift(self.main_db)          def visualize(self, master):             """lifts master upper level"""             master.lift(self.rootframe)             self._visible_ = master          def event_handler(self):             pass          def start_subapp(self, app):             self.visualize(app)             app.activate_content()       class rootframe(tkinter.frame):         """general launcher frame placeholder"""          def __init__(self, parent, *args, **kwargs):             tkinter.frame.__init__(self, parent, *args, **kwargs)              #  var-daclaration             self.widget_fr_opts = dict(relief='sunken', borderwidth=1)             self.widget_grid_opts = dict(sticky=n+e+s+w, padx=1, pady=1)              #  widget-creation             self.image = tkinter.ttk.label(self, text='there centered image right here', anchor='center')              #  widget-design             self.configure(**self.widget_fr_opts)              #  widget-arrangement             self.image.grid(column=0, row=0, **self.widget_grid_opts)              self.grid_columnconfigure(0, weight=1)             self.grid_rowconfigure(0, weight=1)       class navbar(tkinter.frame):         """vertical navbar"""          def __init__(self, parent, *args, **kwargs):             tkinter.frame.__init__(self, parent, *args, **kwargs)              #  var-daclaration             self._info_ = tkinter.stringvar()             self.widget_fr_opts = dict(relief='groove', borderwidth=1)             self.widget_grid_opts = dict(sticky=n+e+s+w, padx=1, pady=1)             self.widget_grid_subopts = dict(sticky=w+n+e, padx=1, pady=1)             self._statusbar = parent.statusbar              #  widget-creation             self._info_.set('menu:\n...menusentences:')             self.textinfo = tkinter.ttk.label(self, textvariable=self._info_)             self.btn_progress = tkinter.ttk.button(self, text='start progress',                                                    command=lambda: self.statusbar_input('starting progress ...'))   # code being started             self.btn_database = tkinter.ttk.button(self, text='database',                                                    command=lambda: parent.start_subapp(parent.main_db))  # database window lifted , content initialized             self.btn_exit = tkinter.ttk.button(self, text='exit', command=parent.quit)              #  widget-design             self.configure(**self.widget_fr_opts)              #  widget-arrangement             self.textinfo.grid(column=0, row=1, **self.widget_grid_subopts)             self.btn_progress.grid(column=0, row=2, **self.widget_grid_subopts)             self.btn_database.grid(column=0, row=3, **self.widget_grid_subopts)             self.btn_exit.grid(column=0, row=4, **self.widget_grid_subopts)              self.grid_columnconfigure(0, weight=1)             self.grid_rowconfigure(0, weight=0)             self.grid_rowconfigure(1, weight=0)             self.grid_rowconfigure(2, weight=0)             self.grid_rowconfigure(3, weight=0)             self.grid_rowconfigure(4, weight=0)          def statusbar_input(self, comm: str):             self._statusbar.start()             self._statusbar._info_.set(comm)       class statusbar(tkinter.frame):         """status-bar @ bottom"""          def __init__(self, parent, *args, **kwargs):             tkinter.frame.__init__(self, parent, *args, **kwargs)              #  var-daclaration             self.prgrvalue = tkinter.intvar()             self._info_ = tkinter.stringvar()             self._user_ = 'some user'             self.widget_fr_opts = dict(relief='sunken', borderwidth=1)             self.widget_grid_opts = dict(padx=1, pady=1)             self.widget_grid_subopts = dict(padx=1, pady=1)  # sticky=w + e,              #  widget-creation             self._info_.set('initializing ...')             self.prgrvalue.set(0)             self.textinfo = tkinter.ttk.label(self, textvariable=self._info_)             self.userinfo = tkinter.ttk.label(self, textvariable=self._user_)             self.progress_ = tkinter.ttk.progressbar(self)             self.btn_move = tkinter.ttk.button(self, text='move it', command=lambda: self.start())  # initial testing, removed later             self.btn_stop = tkinter.ttk.button(self, text='stop it', command=lambda: self.stop())              #  widget-design             self.configure(**self.widget_fr_opts)             self.progress_.configure(length=200, mode='determinate', orient=tkinter.horizontal)              #  widget-arrangement             self.progress_.grid(sticky=w+e, column=0, row=0, **self.widget_grid_subopts)             self.textinfo.grid(column=1, row=0, **self.widget_grid_subopts)             self.userinfo.grid(column=2, row=0, padx=1, pady=1)  # sticky=e,             self.btn_move.grid(column=3, row=0, **self.widget_grid_subopts)             self.btn_stop.grid(column=4, row=0, **self.widget_grid_subopts)             self.grid_columnconfigure(0, weight=1)             self.grid_columnconfigure(1, minsize=200)             self.grid_columnconfigure(2, minsize=200)          def start(self):             # testing             self.progress_.start()          def stop(self):             # testing             self.progress_.stop()       class maindb(tkinter.frame):         """frame visualizing database."""          def __init__(self, parent, *args, **kwargs):             tkinter.frame.__init__(self, parent, *args, **kwargs)              #  var-daclaration             self._activated_ = false             self._source_ = none             self.combotext = tkinter.stringvar()             self.combotext.set('please choose tab...')             self.widget_fr_opts = dict(relief='sunken', borderwidth=1)             self.widget_grid_opts = dict(sticky=n+e+s+w, padx=1, pady=1)              #  widget-creation             #  creation of tools manipulate database             self.toolframe = tkinter.frame(self, width=100, height=50, relief='groove', borderwidth=1)             self.combo = tkinter.ttk.combobox(self.toolframe, textvariable=self.combotext)             # more come              #  creation of database'window             self.dbframe = tkinter.frame(self, width=100, relief='groove', borderwidth=1)             self.db_treeview = tkinter.ttk.treeview(self.dbframe, columns=('size', 'modified'), selectmode='extended')             #  more come              #  widget-design              #  widget-arrangement             self.toolframe.grid(column=0, row=0, sticky=n+e+w, padx=1, pady=1)             self.combo.grid(column=0, row=0, sticky=n+e, padx=1, pady=1)             self.dbframe.grid(column=0, row=1,  sticky=nsew, padx=1, pady=1)             self.db_treeview.grid(column=0, row=0, sticky=nsew, padx=1, pady=1)              self.grid_columnconfigure(0, weight=1)             self.grid_rowconfigure(0, weight=0)             self.grid_rowconfigure(1, weight=1)             self.dbframe.grid_columnconfigure(0, weight=1)             self.dbframe.grid_rowconfigure(0, weight=1, minsize=600)             self.toolframe.grid_columnconfigure(0, weight=1)             self.toolframe.grid_rowconfigure(0, weight=1)          def activate_content(self):             #  contentloading , initializations             pass          def db_connector(self, comm: str, save=false) -> bool:             #  connection code             pass       if __name__ == '__main__':          userscreen = mainapplication.main() 

you neglecting give weight rows or columns in root window. without it, tkinter doesn't know how allocate space when resize window.

def main(cls):     ...     root.grid_rowconfigure(0, weight=1)     root.grid_columnconfigure(0, weight=1) 

since you're putting single widget in root window, recommend using pack since can accomplish in single line.

    self.pack(fill="both", expand=true) 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -