如何使文本框适合其中的文本

2024-04-27 04:44:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Tkinter创建一个简单的界面,但是当我使用insert函数时,我无法使框适应其中文本的大小

root = Tk()
sub_name = Entry(root)
num = Entry(root)
search_type = Entry(root)
flair_name = Entry(root)
comments = Entry(root)

sub_name.insert(0,"Enter the name of a subreddit")
num.insert(1,"enter how many posts you want to check for a specific flair")
search_type.insert(2,"Enter searech type (top - top posts of all time. hot - top posts in the last few days. new - the newest posts")
flair_name.insert(3,"Enter Flair type")
comments.insert(4,"Enter amount of comments you want to analysie per post")


sub_name.pack()
num.pack()
search_type.pack()
flair_name.pack()
comments.pack()


def myclick():
    global sub_name
    global num
    global search_type
    global flair_name
    global comments
    sub_name = sub_name.get()
    num = num.get()
    search_type = search_type.get()
    flair_name = flair_name.get()
    comments = comments.get()
    root.destroy()
            

myButton = Button(root, text="Enter: ", command=myclick)
myButton.pack()

root.protocol(myclick)
root.geometry("500x500")
root.mainloop()

如有任何建议,将不胜感激


1条回答
网友
1楼 · 发布于 2024-04-27 04:44:04

这对你有用吗

sub_name = Text(root)
num = Text(root)
search_type = Text(root)
flair_name = Text(root)
comments = Text(root)
sub_name.insert(‘end’,"Enter the name of a subreddit")
num.insert(‘end’,"enter how many posts you want to check for a specific flair”)
search_type.insert(‘end’,"Enter searech type (top - top posts of all time. hot - top posts in the last few days. new - the newest posts")
flair_name.insert(‘end’,"Enter Flair type")
comments.insert(‘end’,"Enter amount of comments you want to analysie per post")

相关问题 更多 >