pythonbuttontkintervpython

Tkinter Button Not Displaying until loop ends


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.


Solution

  • 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.