为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

qq_花开花谢_0 2023-09-19 15:22:48
我正在开发一个短信应用程序,我用 tkinter 制作了一个简单的 GUI。它有 3 个输入数据的字段和两个按钮。发件人接收者信息我想做的是使消息文本输入比其他文本输入更大,以便用户有更多空间来编写消息(不是很大)。这是我的代码: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.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()
查看完整描述

1 回答

?
Cats萌萌

TA贡献1805条经验 获得超9个赞

您可以使用 Text() 而不是 Entry()。Text() 大小很容易改变。


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 = Text(app, width=20, height=2, font=("Bold",20))

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


查看完整回答
反对 回复 2023-09-19
  • 1 回答
  • 0 关注
  • 81 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信