In the following program, instead of displaying the interfaces one by one, it directly displays the 3rd interface when the Run button is pressed.
import Tkinter
root = Tkinter.Tk( )
root.title("My First Game")
for r in range(3):
for c in range(3):
Tkinter.Label(root, text= '3', borderwidth=20 ).grid(row=1,column=1)
Tkinter.Label(root, text= '6', borderwidth=20 ).grid(row=1,column=2)
Tkinter.Label(root, text= '4', borderwidth=20 ).grid(row=1,column=3)
Tkinter.Label(root, text= '2', borderwidth=20 ).grid(row=2,column=1)
Tkinter.Label(root, text= '7', borderwidth=20 ).grid(row=2,column=2)
Tkinter.Label(root, text= ' ', borderwidth=20 ).grid(row=2,column=3)
Tkinter.Label(root, text= '5', borderwidth=20 ).grid(row=3,column=1)
Tkinter.Label(root, text= '1', borderwidth=20 ).grid(row=3,column=2)
Tkinter.Label(root, text= '8', borderwidth=20 ).grid(row=3,column=3)
def mainprg():
for r in range(3):
for c in range(3):
Tkinter.Label(root, text= '3', borderwidth=20 ).grid(row=1,column=1)
Tkinter.Label(root, text= '6', borderwidth=20 ).grid(row=1,column=2)
Tkinter.Label(root, text= ' ', borderwidth=20 ).grid(row=1,column=3)
Tkinter.Label(root, text= '2', borderwidth=20 ).grid(row=2,column=1)
Tkinter.Label(root, text= '7', borderwidth=20 ).grid(row=2,column=2)
Tkinter.Label(root, text= '4', borderwidth=20 ).grid(row=2,column=3)
Tkinter.Label(root, text= '5', borderwidth=20 ).grid(row=3,column=1)
Tkinter.Label(root, text= '1', borderwidth=20 ).grid(row=3,column=2)
Tkinter.Label(root, text= '8', borderwidth=20 ).grid(row=3,column=3)
B = Tkinter.Button(root, text = "Run", command = mainprg)
B.grid(row = 4, column = 1)
def mainprg1():
for r in range(3):
for c in range(3):
Tkinter.Label(root, text= '3', borderwidth=20 ).grid(row=1,column=1)
Tkinter.Label(root, text= ' ', borderwidth=20 ).grid(row=1,column=2)
Tkinter.Label(root, text= '6', borderwidth=20 ).grid(row=1,column=3)
Tkinter.Label(root, text= '2', borderwidth=20 ).grid(row=2,column=1)
Tkinter.Label(root, text= '7', borderwidth=20 ).grid(row=2,column=2)
Tkinter.Label(root, text= '4', borderwidth=20 ).grid(row=2,column=3)
Tkinter.Label(root, text= '5', borderwidth=20 ).grid(row=3,column=1)
Tkinter.Label(root, text= '1', borderwidth=20 ).grid(row=3,column=2)
Tkinter.Label(root, text= '8', borderwidth=20 ).grid(row=3,column=3)
B = Tkinter.Button(root, text = "Run", command = mainprg1)
B.grid(row = 4, column = 1)
root.mainloop()
What should i do to display a series of interfaces by clicking the Run button?
mainprg1on top of the button that callsmainprg; what did you expect to happen? Again, you should have a look at e.g. stackoverflow.com/a/26213779/3001761 rather than just randomly packing in more widgets. And as @Scironic points out, theforloops are (still) pointless.Runbutton you see is the one that callsmainprg1, not the one that callsmainprg, because you've put the newer button on top of the older one.