python - _tkinter.TclError: cannot use geometry manager grid inside . which already has slaves managed by packenter code here -
i'm trying create child widget based on entry widget. unfortunately it's not working think should. following code:
import tkinter tk window_width = 800 window_height = 600 class application(tk.frame): def __init__(self, master=none): tk.frame.__init__(self, master) self.pack() self.createwidgets() def createwidgets(self): self.hi_there = tk.button(self) self.hi_there["text"] = "solve" self.hi_there.grid(row=1, column=1) self.quit = tk.button( self, text="quit", fg="red", command=self.master.quit) self.quit.grid(row=1, column=2) # self.number_box = tk.entry(self) # working self.number_box = numberbox(self) # not working self.number_box.grid(row=2, column=1) class mainwindow(): def __init__(self): #self.root = tk.tk() self.app = application() self.app.master.title("sudoku") self.app.master.minsize(width=window_width, height=window_height) self.app.master.maxsize(width=window_width, height=window_height) self.app.mainloop() class numberbox(tk.entry): def __init__(self, master=none, cnf={}, **kw): super().__init__(cnf, kw) #self.text = tk.stringvar() window = mainwindow()
i error:
traceback (most recent call last): file "e:/workspace/python/sudoku/gui/guitk.py", line 42, in <module> window = mainwindow() file "e:/workspace/python/sudoku/gui/guitk.py", line 28, in __init__ self.app = application() file "e:/workspace/python/sudoku/gui/guitk.py", line 11, in __init__ self.createwidgets() file "e:/workspace/python/sudoku/gui/guitk.py", line 22, in createwidgets self.number_box.grid(row=2, column=1) file "c:\python34\lib\tkinter\__init__.py", line 2057, in grid_configure + self._options(cnf, kw)) _tkinter.tclerror: cannot use geometry manager grid inside . has slaves managed packenter code here
when use entry class directly (not numberbox, see commented line), code working. wrong inheritance entry class not working properly.
your super()
call looks wrong. need pass parent widget , pass unpacked keyword arguments, this:
super().__init__(master, cnf, **kw)
Comments
Post a Comment