如何使 tkinter 上的输入文本区域变大?

我正在开发一个短信应用程序,我用 tkinter 制作了一个简单的 GUI。它有 3 个输入数据的字段和两个按钮。

  1. 发件人

  2. 接收者

  3. 信息

我想做的是使消息文本输入比其他文本输入更大,以便用户有更多空间来编写消息(不是很大)。

这是我的代码:

from tkinter import *


def send_message():

    print('sent')


def clear_text():

    print('cleared')


#window object

app = Tk()

# Sender

Sender_text = StringVar()

Sender_label = Label(app, text='Sender', font=('bold', 14), pady=20)

Sender_label.grid(row=0, column=0, sticky=W)

Sender_entry = Entry(app, textvariable=Sender_text)

Sender_entry.grid(row=0, column=1)

# Receiver

Receiver_text = StringVar()

Receiver_label = Label(app, text='Receiver', font=('bold', 14))

Receiver_label.grid(row=0, column=2, sticky=W)

Receiver_entry = Entry(app, textvariable=Receiver_text)

Receiver_entry.grid(row=0, column=3)

# Message

Message_text = StringVar()

Message_label = Label(app, text='Message', font=('bold', 14))

Message_label.grid(row=1, column=0, sticky=W)

Message_entry = Entry(app, textvariable=Message_text)

Message_entry.grid(row=1, column=1)

# Buttons

send_btn = Button(app, text='Send', width=12, command=send_message)

send_btn.grid(row=2, column=0, pady=20)

clear_btn = Button(app, text='Clear', width=12, command=clear_text)

clear_btn.grid(row=2, column=1)



app.title('SMS')

app.geometry('430x145')


#start

app.mainloop()


qq_花开花谢_0
浏览 82回答 1
1回答

Cats萌萌

您可以使用 Text() 而不是 Entry()。Text() 大小很容易改变。from tkinter import *def send_message():    print('sent')def clear_text():    print('cleared')#window objectapp = Tk()# SenderSender_text = StringVar()Sender_label = Label(app, text='Sender', font=('bold', 14), pady=20)Sender_label.grid(row=0, column=0, sticky=W)Sender_entry = Entry(app, textvariable=Sender_text)Sender_entry.grid(row=0, column=1)# ReceiverReceiver_text = StringVar()Receiver_label = Label(app, text='Receiver', font=('bold', 14))Receiver_label.grid(row=0, column=2, sticky=W)Receiver_entry = Entry(app, textvariable=Receiver_text)Receiver_entry.grid(row=0, column=3)# MessageMessage_text = StringVar()Message_label = Label(app, text='Message', font=('bold', 14))Message_label.grid(row=1, column=0, sticky=W)#Message_entry = Entry(app, textvariable=Message_text)Message_entry = Text(app, width=20, height=2, font=("Bold",20))Message_entry.grid(row=1, column=1)# Buttonssend_btn = Button(app, text='Send', width=12, command=send_message)send_btn.grid(row=2, column=0, pady=20)clear_btn = Button(app, text='Clear', width=12, command=clear_text)clear_btn.grid(row=2, column=1)app.title('SMS')app.geometry('430x145')#startapp.mainloop()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python