I have a button that pops up an options window, when I try to populate the widgets on the new window they only appear on the parent window.
here is the related code:
from Tkinter import *
class MainWindow:
def __init__(self, master):
"""builds main window."""
windowAttr = {"width":450, "height":150}
window = Frame(master, windowAttr).grid()
btnAttr = {"text":"Options", "width":12, "height":1}
self.btnOptions = Button(window, btnAttr, command=btnOptionsClick).place(x=360, y=5)
class Options:
def __init__(self, optMaster):
"""Builds and displays the options window"""
optAttr = {"width":300, "height":200}
optWin = Frame(optMaster, optAttr).grid()
self.chkMon = Checkbutton(optWin, text="Mon").place(x=50, y=50)
def btnOptionsClick():
opt = Tk(className='Options')
optionsApp = Options(opt)
opt.mainloop()
root = Tk(className='Main Window')
app = MainWindow(root)
root.mainloop()
chkMon appears on MainWindow and Options is always empty, I want chkMon to appear on Options and not on MainWindow.
I’m very new to python so I’m thankful for any help knowledgeable folks have.
edit:
I found a working solution, remove the Options class and change def btnOptionsClick() to:
def btnOptionsClick():
opt = Toplevel(root, takefocus=True)
chkMon = Checkbutton(opt, text="Mon").place(x=50, y=50)
Try making the first line of your original btnOptionsClick() function be …
and then leave the rest as it was.