为什么不显示文字

时间:2013-07-27 09:16:42

标签: python python-3.x tkinter

我正在尝试创建一个程序,您在输入框中键入文本,然后当您单击按钮时它会显示下面的文本,但它不起作用,只要我点击它给我的按钮错误?

import sys
from tkinter import *

def myhello():
    text = ment.get()
    label = Label(text=entry).grid()
    return

ment = str()
root = Tk()
root.title('Tutorial')
root.geometry('400x400')

button = Button(root, text='Button',command = myhello).place(x='160', y='5')

entry = Entry(textvariable=ment).place(x='5', y= '10 ')

root.mainloop()

1 个答案:

答案 0 :(得分:2)

您应该使用StringVar,而不是str

您正在同时使用gridplace。选一个。

import sys
from tkinter import *

def myhello():
    text = ment.get()
    label['text'] = text

root = Tk()
root.title('Tutorial')
root.geometry('400x400')

button = Button(root, text='Button',command=myhello).place(x='160', y='5')
label = Label(root, text='')
label.place(x=5, y=30)

ment = StringVar()
entry = Entry(textvariable=ment).place(x='5', y= '10 ')

root.mainloop()
相关问题