添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

如何在使用网格系统时,在tkinter中改变Entry高度,并添加文本包覆?

0 人关注

我正在做一个发送电子邮件的gui程序。我想添加一个条目(我代码中的messageEntry)来输入信息。我想改变它的高度,这样信息就不必在一行中输入了(我想有文本包装)。我试着使用ipady,它确实调整了条目的大小,但信息仍然只能在一行中输入(在条目的中间)。以下是我的代码。

def sendMail(senderEmail, senderPassword):
    global server
    sendMailFont = ['Consolas', 10]
    sendMailWindow = Tk()
    sendMailWindow.title("Sendmail")
    sendMailWindow.resizable(False, False)
    sendMailWindow.focus_force()
    # sendMailWindow.iconbitmap('info icon.ico')
    sendMailWindow.config(bg = "#DCDCDC")
    loggedInLabel = Label(sendMailWindow, font = (sendMailFont), text = "Logged in as {}".format(senderEmail), bg = "#DCDCDC")
    loggedInLabel.grid(row = 0, column = 0)
    subjectLabel = Label(sendMailWindow, font = (sendMailFont), text = "Subject", bg = "#DCDCDC")
    subjectLabel.grid(row = 2, column = 0, sticky = "w")
    subjectEntry = Entry(sendMailWindow, font = (sendMailFont), bg = "#FFFFFF", width = 37)
    subjectEntry.grid(row = 3, column = 0, sticky = "w", ipady = 2)
    messageLabel = Label(sendMailWindow, font = (sendMailFont), text = "Message", bg = "#DCDCDC")
    messageLabel.grid(row = 5, column = 0, sticky = "w")
    messageEntry = Entry(sendMailWindow, font = (sendMailFont), bg = "#FFFFFF", width = 37)
    messageEntry.grid(row = 6, column = 0, sticky = "w")
    hiddenLabel = Label(sendMailWindow, font = ('Consolas', 1), text = "", bg = "#DCDCDC")
    hiddenLabel.grid(row = 1, column = 0, sticky = "we")
    hiddenLabel = Label(sendMailWindow, font = ('Consolas', 10), text = "", bg = "#DCDCDC")
    hiddenLabel.grid(row = 4, column = 0, sticky = "we")
    sendMailWindow.mainloop()
    
1 个评论
而条目小部件只能是一行。如果你想要更多行,请使用 Text
python
tkinter
label
Andrej
Andrej
发布于 2020-05-30
1 个回答
D_00
D_00
发布于 2020-05-31
已采纳
0 人赞同

你可以像这样使用 tkinter.scrolledtext 模块。

from tkinter import *
from tkinter.scrolledtext import *
def sendMail(senderEmail, senderPassword):
    global server
    sendMailFont = ['Consolas', 10]
    sendMailWindow = Tk()
    sendMailWindow.title("Sendmail")
    sendMailWindow.resizable(False, False)
    sendMailWindow.focus_force()
    # sendMailWindow.iconbitmap('info icon.ico')
    sendMailWindow.config(bg = "#DCDCDC")
    loggedInLabel = Label(sendMailWindow, font = (sendMailFont), text = "Logged in as {}".format(senderEmail), bg = "#DCDCDC")
    loggedInLabel.grid(row = 0, column = 0)
    subjectLabel = Label(sendMailWindow, font = (sendMailFont), text = "Subject", bg = "#DCDCDC")
    subjectLabel.grid(row = 2, column = 0, sticky = "w")
    subjectEntry = Entry(sendMailWindow, font = (sendMailFont), bg = "#FFFFFF", width = 37)
    subjectEntry.grid(row = 3, column = 0, sticky = "w", ipady = 2)
    messageLabel = Label(sendMailWindow, font = (sendMailFont), text = "Message", bg = "#DCDCDC")
    messageLabel.grid(row = 5, column = 0, sticky = "w")
    ##########
    messageEntry = ScrolledText(sendMailWindow, font = (sendMailFont), bg = "#FFFFFF", width = 37, height = 5)
    messageEntry.grid(row = 6, column = 0, sticky = "w")
    ##########