【问题标题】:Why does .get give me PY_VAR0 instead of the string为什么 .get 给我 PY_VAR0 而不是字符串
【发布时间】:2020-01-20 06:57:33
【问题描述】:

班级Two_players():

def __init__(self):
    self.player1=StringVar()
    self.player2=StringVar()
    self.window1=Tk()
    self.window1.title("Spieler Eingabe")
    self.window1.geometry("500x600")
    self.label_01=Label(self.window1, text="Spieler eingabe",width=25, relief="solid", font=("arial",12,"bold")).pack()
    self.entry_1 = Entry(self.window1,text=self.player1).place(x=170, y=153)
    self.label_03=Label(self.window1, text="Spieler 1 : ", font=("arial",12,"bold")).place(x=80,y=150)
    self.label_04=Label(self.window1, text="Spieler 2 : ", font=("arial",12,"bold")).place(x=80,y=180)
    self.entry_2 = Entry(self.window1,text=self.player2).place(x=170, y=183)
    self.but_01=Button(self.window1,text="wörter eingeben",width=15,bg="black",fg="green", command= lambda :  self.two_players_words()).place(x=200,y=500)

问题出在label_21 - 我希望输出是entry_1,但它只显示py_var0

我已经用 .get 尝试过,但这也没有帮助:

def two_players_words(self):

    window1=Tk()
    window1.title("Wörter Eingabe")
    window1.geometry("500x600")
    label_20=Label(window1, text="Wörter eingabe",width=25, relief="solid", font=("arial",12,"bold")).pack()
    label_21=Label(window1,text=self.player1, font=("arial",12,"bold")).place(x=80,y=150)
    entry_15 = Entry(window1,textvar=word1).place(x=170, y=153)
    label_22=Label(window1, text="{player2} : ", font=("arial",12,"bold")).place(x=80,y=180)
    entry_16 = Entry(window1,textvar=word2).place(x=170, y=183)

【问题讨论】:

    标签: python-3.x class user-interface tkinter tkinter-entry


    【解决方案1】:

    使用textvariable 参数而不是文本

    label_21=Label(window1,textvariable=self.player1, font=("arial",12,"bold")).place(x=80,y=150)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-10
      • 1970-01-01
      • 2020-10-15
      • 1970-01-01
      • 1970-01-01
      • 2018-06-08
      • 2019-01-19
      相关资源
      最近更新 更多