In my program i have tried to get a Tk window to come up yet it does not come up.
I have called my window root and i have put in an event loop, yet it still does
show. I have looked all over the internet for a solution but it appers to cease
to exist.
This is a code snippet from the beggining of the program:
def NumberGuessingGame():
z = 0
b = True
h = 0
name = 1
root = Tk()
frame1 = Frame( root, width = 400, height = 400 )
credits = Label( frame1, text = 'NumberGuessingGame.\nAuthor: ***********\nVersion: 6.0', fg = 'red' )
credits.grid(row = 0)
and this is the code snippet from the end of the program:
v2 = True
while v2 == True:
v1 = input( 'Would you like to play the game? ' )
if v1 == 'y' or v1 == 'yes':
NumberGuessingGame()
continue
elif v1 == 'n' or v1 == 'no':
print( 'The game will now exit.' )
break
else:
print( 'The game will now exit.' )
break
input( "Press <ENTER> to close program." )
root.mainloop()
.mainloop()
your code-logic preceding the root.mainloop()
fortunately prevents from entering the Tkinter GUI
you need contructor like so:
def __init__(root):
this makes your code be able to run and call root.mainloop()
to make a tk window
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.