我想做一个简单的句子生成器。代码可以工作,但我只想知道是否有任何方法可以扩展GUI输入框?你知道吗
它看起来是这样的:
任何帮助都将不胜感激。你知道吗
import tkinter as tk
from tkinter import Entry
import random
window = tk.Tk()
def movingVerb():
verbs = ["goes to", "walks through", "runs through"]
moveVerb = random.choice(verbs)
return moveVerb
def anObject():
anObject = objectEntry.get()
def Generate():
UserName = nameEntry.get()
moveVerb = movingVerb()
place = placeEntry.get()
noun = objectEntry.get()
sentence = UserName + " " + moveVerb + " a " + place + " and finds a " + noun + " ."
result.delete(0, tk.END)
result.insert(0, sentence)
UserNameLabel = tk.Label(window, text="Enter a name: ")
nameEntry = tk.Entry(window)
anObjectLabel = tk.Label(window,text="Enter an object: ")
objectEntry = tk.Entry(window)
placeLabel = tk.Label(window, text="Enter a place: ")
placeEntry = tk.Entry(window)
button = tk.Button(window, text="Generate story", command=Generate)
result = tk.Entry(window)
UserNameLabel.pack()
nameEntry.pack()
anObjectLabel.pack()
objectEntry.pack()
placeLabel.pack()
placeEntry.pack()
button.pack()
result.pack()
window.mainloop()
用地方而不是包装,你可以在这里做这个甜蜜的方法。你知道吗
如果要在调整窗口大小时展开窗口小部件,则可以在
pack()
中以不同的组合使用expand
和fill
。这一切都取决于你想扩展的元素和方向。你知道吗如果要调整窗口大小以查看
Entry
中的所有新文本,则可以使用widget.configure(width=...)
。条目使用字符数作为宽度。你知道吗你可以用句子的长度来改变宽度
或者保持宽度至少20个字符
完整代码
相关问题 更多 >
编程相关推荐