0

入力ボックスにテキストを入力し、ボタンをクリックすると下にテキストが表示されるプログラムを作成しようとしていますが、ボタンをクリックするとすぐにエラーが発生しますか?

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()
4

1 に答える 1

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()
于 2013-07-27T09:21:02.240 に答える