0

I have a small app on Linux in which I sub-class the Frame class from tkinter and sometime the widgets are only drawn after I press the alt button. Everything works fine, though this is the first time I use this GUI and I may miss something.

Follows a short example of my code:

from tkinter import *

class MyFrame(Frame):   
    def one_method(self):
        root_frame.geometry("200x400")
        button = Button(self, command=self.clean_and_draw_more_widget, text="Hello")
        button.pack(side=TOP) #I also use grid()

the main driver code:

root_frame = Tk()
root_frame.title("Window")  
 
frame = MyFrame(root_frame)
frame.pack()

root_frame.mainloop()

As you can see nothing compless, but still I have this problem.

EDIT I use grid() and pack() but each one in different methods

Thanks for helping

  • "click the alt button" - Do you mean "press the Alt key on my keyboard ? – TheEagle May 01 '21 at 13:49
  • "pack(side=TOP) #I also use grid()" - Never do that. Choose one of them, and stick with it. – TheEagle May 01 '21 at 13:49
  • Have you looked at how `tkinter` bindings work? – TheLizzard May 01 '21 at 13:50
  • @Programmer I disagree. I think OP is saying that they might use either `.pack` or `.grid`. You don't have to pick one and stick with it for the whole project. You can have different geometry managers in each `tkinter.Tk`/`tkinter.Frame`/`tkinter.Toplevel`. – TheLizzard May 01 '21 at 13:51
  • And please create a [Minimal Reproducible ___Runnable___ Example](https://stackoverflow.com/help/minimal-reproducible-example) – TheEagle May 01 '21 at 13:51
  • @TheLizzard no, you don't have to stick to one for the whole project, but you can't use `pack` and `grid` on the same widget. The OP should reformulate that code comment to make clear whether he uses both methods in his project or on the same widget. – TheEagle May 01 '21 at 13:53
  • @Programmer I think OP already knows that and I can't see any evidence of OP using both `.pack` and `.grid` in their `MyFrame` class. It looks like OP will either `.pack` or `.grid` in that frame but for simplification purposes OP chose `.pack`. – TheLizzard May 01 '21 at 13:56
  • @TheLizzard I cannot use it :( – Antonio Molinaro May 01 '21 at 14:04
  • @AntonioMolinaro Use `.bind(, )`, where `` can be any of [these](https://stackoverflow.com/questions/32289175/list-of-all-tkinter-events) – TheLizzard May 01 '21 at 14:12
  • @TheLizard I dont use bind() because as I said above I can't use it – Antonio Molinaro May 01 '21 at 14:16
  • @AntonioMolinaro That is why I am trying to explain it. Using `tkinter` without `.bind` can be very very difficult. If you want to know how it works look at [this](https://codereview.stackexchange.com/a/193357) as well – TheLizzard May 01 '21 at 14:19
  • @TheLizzard You saying that each command must be bind to the root Frame ? – Antonio Molinaro May 01 '21 at 14:23
  • @AntonioMolinaro You can to any function to any tkinter widget. Also the code that you have given works fine. What do you mean by *"the widgets are only drawn after I press the `alt` button."*? Do they just not appear on your screen? What Python/Tcl versions do you have? – TheLizzard May 01 '21 at 14:26
  • @TheLizzard Yes the frame is completely empty(gray) and the version is 8.6 – Antonio Molinaro May 01 '21 at 14:34
  • @AntonioMolinaro What OS are you using? If you are using python 3.x on Windows 10 try reinstalling python. – TheLizzard May 01 '21 at 14:35
  • @TheLizzard I use Ubuntu linux and python3 – Antonio Molinaro May 01 '21 at 14:36

0 Answers0