我一直在试图找到解决此问题的方法,但是我似乎陷入了困境。我试图从一个类的用户(他们的名字)中输入条目,然后将该条目输入到另一个类的标签中,这样我就可以创建一个基于文本的游戏。这是我现在的代码的简化形式:
from tkinter import *
class Page6(Tk):
def Page6():
window=Toplevel()
window.geometry("1920x1080")
window["bg"] = ("#FFB6C1")
window.title("Dating Simulator")
iag = PhotoImage(file="Images\ClassroomTextBoxThree.gif")
labelfour = Label(window, image=iag)
labelfour.place(x=-100,y=-50)
labelfour.photo = iag
textThree = Label(window, text ="Hello What is your Name?", font= "Times 15")
textThree.place( x = 80, y = 60)
#add name to code/username below
#the code below is where I want to retrieve the input from class Page2
MyButton1 = Button(window, text="Hello my name is" + E1.get(), width=10, font="Times 20", command=Page7.Page7)
MyButton1.place(x=1120, y=275)
class Page2(Tk):
def Page2():
window=Toplevel()
window.geometry("1920x1080")
window["bg"] = ("#FFB6C1")
window.title("Dating Simulator")
imag = PhotoImage(file="Images\Minami.gif")
labelthree = Label(window, image=imag)
labelthree.place(x=-100,y=-50)
labelthree.photo = imag
#labelthree.pack(side="right")
#E1 is where the user should input their name
E1 = Entry(window, bd = 5)
E1.place(x=1100, y= 675)
EntryOne = Label(window, text = "Please insert your name (First name only):", font = "Times 20", bg ="#ffffff")
EntryOne.place(x=600,y=200)
MyButton1 = Button(window, text="Submit", width=10, font="Times 20", command=Page3.Page3)
MyButton1.place(x=1090, y=725)
我尝试从其他帖子中查找其他解决方案,但要么只涉及从一个类中获取数据,要么仅涉及一个变量,而不涉及条目输入。工作产品应使按钮(来自第6类)的按钮包括来自第2类的用户输入的名称作为其文本的一部分。非常感谢您阅读。