from tkinter import *
def corequiz():
Guess.get()
global Guess_num
Guess_num = Guess_num + 1
if song == Guess:
print("congratulations the song was " + song)
if Guess_num == 1:
print("well done " + name + " you guessed it on your first try")
User_score = User_score + 3
print(name + " your points are " + str(User_score))
elif Guess_num == 2:
print("well " + name + " you did it on your second try")
User_score = User_score + 1
else:
print("you failed to answer the question")
print("your current points are " + str(User_score))
else:
print("wrong")
def Quiz(name,User_score,artist,song):
root = Tk()
root.title("game")
root.geometry("720x500+0+0")
heading = Label(root, text="welcome to the quiz game",font=("arial",24,"bold"),fg = "black").pack()
tip = Label(root, text=("this song is by " + artist + " and the first few letters of the song is: " + song[0] + song[1]),font=("italics",10,"normal"),fg = "black").place(x=10,y=50)
usernameenter = heading = Label(root, text="enter your guess of the song: ",font = ("arial",11,"bold"),fg="black").place(x=10,y=100)
Guess = StringVar()
entry_box2 = Entry(root, textvariable= Guess,width=80,bg="light blue").place(x=222,y=105)
entryguess = Button(root, text="Submit",width=30, height=3,bg="lightblue",command=corequiz).place(x=250,y=200)
root.mainloop()
#theses are example variables
global Guess_num
Guess_num = 0
global song
song = "shake it off"
global artist
artist = "Taylor swift"
global User_score
User_score = 1
global name
name = "gamer"
Quiz(name,User_score,artist,song)
я новичок в tkinter.
я не могу получить этот код, чтобы заставить Guess перейти на подпрограмму corequiz.
как я могу получить guess.get ()чтобы получить переменную из поля ввода, когда вы нажимаете кнопку, которая предназначена для подпрограммы corequiz.
Я попытался создать глобальные переменные и сделать их не внутри подпрограммы. Но ничего из этого не работает, Guess просто выводит, что Guess не определен из Guess.get ().
этот код для моего проекта программирования, который я делаю. Что такое викторина песни Gui: если пользователь правильно понял, в первый раз его 3 балла, второй 1 балл и в третий раз закройте программу. Это работает на Python 3.7