【发布时间】:2020-04-24 18:46:17
【问题描述】:
我一直在寻求帮助,但找不到任何我需要的东西.. 我有一些看起来像这样的东西:
因此,当用户输入配料时,它会在线为您提供食谱。在这里,我想修复文本框,因为它只显示一行。当我打印输出时,它包含一个新行并且看起来更好但是一旦我将它插入到输入框中,它会忽略所有新行和空格。 这是我的接口代码:
# Driver code
if __name__ == "__main__":
# create a GUI window
master = tk.Tk()
s = tk.StringVar()
field1 = tk.Entry(master, textvariable=s)
field1.config({"background": "LightBlue1", "disabledbackground": "LightSkyBlue1"})
field2 = tk.Entry(master)
field2.config({"background": "Ivory", "disabledbackground": "Ivory"})
field1.place(x=20, y=20, width=660, height=40)
field2.place(x=20, y=80, width=660, height=500)
field1.configure(state='disabled')
field2.configure(state='disabled')
# set font
myFont = font.Font(family='Verdana', size=9, weight='bold')
# set text message for cavas
text = "Welcome to Recipe Finder!\n" \
+ "Instruction: Click the colored button,\n" \
+ "Type either sentence or words\n" \
+ "into the light blue box."
canvas = tk.Canvas(master, width=250, height=100, bg='DodgerBlue4')
canvas.pack()
canvas.place(x=700, y=40)
canvas.create_text(125, 50, fill="white", font=myFont, text=text)
# set the background colour of GUI window
master.configure(background="lemon chiffon")
# set the title of GUI window
master.title("Recipe Finder")
# set the configuration of GUI window
master.geometry("970x600")
# Buttons
button1 = tk.Button(master, text=' Click for some food jokes! ', fg='black', bg='salmon',
command=foodJokes, height=5, width=30)
button1.place(x=700, y=200)
button1['font'] = myFont
button2 = tk.Button(master, text=' Type the ingredients you have! ', fg='black', bg='orange',
command=askForIngredients, height=5, width=30)
button2.place(x=700, y=300)
button2['font'] = myFont
Clear = tk.Button(master, text=' CLEAR ', fg='black', bg='white',
command=clear, height=5, width=30)
Clear.place(x=700, y=400)
Clear['font'] = myFont
Enter = tk.Button(master, text=' ENTER ', fg='black', bg='white',
command=enter, height=5, width=30)
Enter.place(x=700, y=500)
Enter['font'] = myFont
虽然有人告诉我使用“grid”更简单更好,但我发现“place”对我来说效果更好......而且我只看到使用 grid 和 pack 的帖子,我不想改变我的所有此时的设置。有没有一种简单的方法可以将输入文本更改为在框内换行?
【问题讨论】: