Mar-05-2019, 08:58 PM
I quickly reviewed your code and have a couple observations:
Make a class and eliminate your globals
initiate Tk once not 3 times:
you have multiple ways to create other free standing widgets:
create a separate frames
use simpledialogs-
example:
then compare guess to your random number...
Make a class and eliminate your globals
initiate Tk once not 3 times:
you have multiple ways to create other free standing widgets:
create a separate frames
use simpledialogs-
example:
from tkinter.simpledialog import * from tkinter import * if __name__ == '__main__': def test(): root = Tk() def doit(root=root): d = SimpleDialog(root, text="This is a test dialog. " "Would this have been an actual dialog, " "the buttons below would have been glowing " "in soft pink light.\n" "Do you believe this?", buttons=["Yes", "No", "Cancel"], default=0, cancel=2, title="Test Dialog") print(d.go()) print(askinteger("Spam", "Egg count", initialvalue=12*12)) print(askfloat("Spam", "Egg weight\n(in tons)", minvalue=1, maxvalue=100)) print(askstring("Spam", "Egg label")) t = Button(root, text='Test', command=doit) t.pack() q = Button(root, text='Quit', command=t.quit) q.pack() t.mainloop() test()this example is from the simpledialog module. you could-
guess= askinteger("your guess", "Number 1-10", initialvalue=1)
then compare guess to your random number...