python - tkinter 不能 .get() 文本变量
问题描述
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 子例程。
当您单击猜测子程序 corequiz 的按钮时,我如何才能让guess.get() 从输入框中实际获取变量。
我尝试过制作全局变量并使其不在子程序中。但是这些都不起作用 Guess 只是输出 Guess 不是从 Guess.get() 定义的。
这段代码适用于我正在做的编程项目。这是gui song quiz:如果用户第一次做对了它的3分,第二个1分和第三次关闭程序。这是在 python 3.7 上运行的
解决方案
推荐阅读
- r - 如何在 R 中安装 Prophet 包
- python - 如何使用烧瓶 API 保存图像然后将其返回到我的 React 应用程序可以使用它
- node.js - 如何使用 puppeteer 下载 PDF blob?
- javascript - 基于不在查询中的数据的 Firebase 实时数据库规则
- css - 无法在 react-bootstrap 中正确显示视频组件
- javascript - Javascript - 我如何比较数组的两个对象?
- javascript - 这个递归如何解决爆炸求和函数
- java - 测试录制和播放时 Android Studio 4 模拟器中的应用程序崩溃
- python - 如何将熊猫日期时间对象的时间更改为小时的开始?
- c - 使用预处理器将外部函数指针更改为外部指针