'Why does commands of buttons on tkinter doesn't work
So I'm trying to create turtles racing but with different windows at the same time. The play and exit buttons work but when I pick a color, nothing happens. Here's some of my code.
P.S I didn't add all of them because stack overflow wouldn't allow many codes
#miscellaneous
play = True
player = ' '
so these are the functions
def hide_frames():
frame1.pack_forget()
frame2.pack_forget()
frame3.pack_forget()
def chosen1():
player = 't1'
hide_frames
frame3.pack()
def chosen2():
player = 't2'
hide_frames
frame3.pack()
def chosen3():
player = 't3'
hide_frames
frame3.pack()
def chosen4():
player = 't4'
hide_frames
frame3.pack()
def chosen5():
player = 't5'
hide_frames
frame3.pack()
def chosen6():
player = 't6'
hide_frames
frame3.pack()
def chosen7():
player = 't7'
hide_frames
frame3.pack()
def chosen8():
player = 't8'
hide_frames
frame3.pack()
def chosen9():
player = 't9'
hide_frames
frame3.pack()
def playy():
hide_frames()
play = False
frame2.pack()
and these are my buttons
button1 = Button (frame2, text = 'green', fg = 'green', command = chosen1)
button2 = Button (frame2, text = 'blue', fg = 'blue', command = chosen2)
button3 = Button (frame2, text = 'red', fg = 'red', command = chosen3)
button4 = Button (frame2, text = 'yellow', fg = 'yellow', command = chosen4)
button5 = Button (frame2, text = 'orange', fg = 'orange', command = chosen5)
button6 = Button (frame2, text = 'indigo', fg = 'indigo', command = chosen6)
button7 = Button (frame2, text = 'violet', fg = 'violet', command = chosen7)
button8 = Button (frame2, text = 'maroon', fg = 'maroon', command = chosen8)
button9 = Button (frame2, text = 'magenta', fg = 'magenta', command = chosen9)
I already pack() the buttons but I didn't include it here because it will be too long
def start():
t1.goto(400, 400)
t2.goto(400, 300)
t3.goto(400, 200)
t4.goto(400, 100)
t5.goto(400, 0)
t6.goto(400, -100)
t7.goto(400, -200)
t8.goto(400, -300)
t9.goto(400, -400)
#buttons
play_button = Button(frame1, text = 'Play', command = playy).pack(side = TOP)
exit_button = Button(frame1, text = 'Quit', command = root.quit).pack(side = TOP)
label = Label(frame2, text = 'please pick your color')
label.pack()
start_button = Button(frame3, text = 'START!', command = start)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
