python - Why does ttk.Button appears in the main window instead of tk.Toplevel? -
i have main ui gets instantiated this:
class myapp(ttk.frame): def __init__(self, master): ttk.frame.__init__(self, master) (...) def make_gui(self): (...) self.helpbutt = ttk.button(self.innerrightfrm2, padding=(0, 0), text='help', image=help_icon compound='left', command=self.show_help) (...) def main(): root = tk.tk() root.title('myapp') root.columnconfigure(0, weight=1) root.rowconfigure(0, weight=1) root.resizable(true, true) root.update() gui = myapp(root) gui.mainloop()
when user clicks show help
button located on main interface new toplevel
window should appear. toplevel
of window contains 2 frames: topframe0
on row=0
, topframe1
on row=1
. create third frame inside topframe1
put "close" button in in. here how it:
def show_help(): top_win = tk.toplevel() top_win.title('help') top_win.resizable(0, 0) topframe0 = ttk.frame(top_win, borderwidth=2, relief='groove') topframe0.grid(row=0, column=0, sticky='nsew') topframe1 = ttk.frame(top_win, borderwidth=2, relief='flat') topframe1.grid(row=1, column=0, sticky='nsew') buttonframe = ttk.frame(topframe1, borderwidth=2, relief='groove').grid() ttk.button(buttonframe, padding=(0, 2), text='close', command=top_win.destroy).grid(sticky='e')
however, instead of appearing in right botton of toplevel
window (notice red arrow in screenshot), "close" button appears in right bottom of main myapp
window! how can happen?
in line
buttonframe = ttk.frame(...).grid()
you assign none
buttonframe
because grid()
returns none
have later ttk.button(none, ...)
, add button main window.
you need
buttonframe = ttk.frame(...) buttonframe.grid()
Comments
Post a Comment