I am currently learning python and have hit a roadblock. I started in java and enjoyed the use of JOptionPane for input dialogs, and using those dialogs to assign values to variables and parsing them from there.
In python I've noticed people use Tkinter for most basic gui set-ups, but I could not find a lot of information on how to use a text box created with tkinter to assign a value to a variable. My code is as follows:
import random
import tkinter as tk
def guess():
global entry
guess = entry.get()
guessN = int(guess)
root1 = tk.Tk()
label = tk.Label(root1, text='What number am I thinking of between 1 and 100?')
entry = tk.Entry(root1)
entry.focus_set()
b = tk.Button(root1,text='okay',command=guess)
b.pack(side='bottom')
label.pack(side = tk.TOP)
entry.pack()
root1.mainloop():
x = random.randint(1,101)
guess()
tries = 0
while guessN != x:
if (guessN < x):
guess = input("Too low! Try again.")
guessN = int(guess)
tries += 1
else:
guess = input("Too high! Try again.")
guessN = int(guess)
tries += 1
print('Congratulations you guessed the number', x, 'in', tries, 'tries!')
SystemExit
I want to use tkinter to assign the input to guess and then use guessN to check against the randomly generated number. I'm not really sure where to go from here, or how to continuously check, and re-assign the variable if the guess was not correct.