0
if __name__ == "__main__":
loop = True
loggedIn = False
vsbl = None#Assign None type
root = Tk()
Cube.displaying()
btn_rr = ttk.Button(root, text="right forward")
btn_rr.pack()
btn_rr.config(command = lambda: Cube.rotate_right("forward"))
while loop:

I am building a Rubik's Cube program - I want to add buttons. The module I am using is called VPython. Whether I place the buttons inside or outside the loop they won't display until I close the VPython window.

furas
  • 134,197
  • 12
  • 106
  • 148
Governor
  • 300
  • 1
  • 10
  • 2
    `while` and `sleep` block tkinters mainloop. This causes the GUI to freeze until they complete. You will have to refactor your code to use `after` or use threading to handle your loop. That said please provide a testable example. – Mike - SMT Feb 21 '20 at 18:24
  • 2
    `tkinter` (like other GUI framework) has own loop - `root.mainloop()` - which has to run all time and if you run other loop then it blocks mainloop and it can't update/redraw widgets in window. You may have to run other loop in thread or you may try to use `after(milliseconds, function)` to run single loop periodically. Eventually you can use `root.update()` in other loop ro force tkinter to redraw/update window. – furas Feb 22 '20 at 03:58

1 Answers1

1

I would like to echo @furas comment about how tkinter has its own loop - root.mainloop() If you are running code simultaneously with a tk.raise() or other tkinter modules, you will need to use the root.update().

The more you stay away from needing these root.update() lines, the better, but sometimes it can't be avoided.