我在高中学习python,所以如果我的问题的答案看起来很明显或者我的代码太草率,我很抱歉
我正在使用python中的tkinter创建一个窗口,用户可以在其中放入他所拥有的配料,当单击“确认”时,该窗口将在画布中显示他们可用的配方。下面是它目前的样子(抱歉,语言是法语,但应该可读)
我的代码是这样的:
def takequantity():
mondico["Tomate"] = saisirtomate.get()
mondico["Fromage"] = saisirfromage.get()
mondico["Farine"]= saisirfarine.get()
#I copy and paste this as many times as I need for about 20 ingrediants
if (mondico["Tomate"]>=5 and
mondico["Farine"]>=500 and
mondico["Fromage"]>=50):
recette=can.create_text(300, 200, text="Pizza")
#basically, if the ingrediants pass a certain threshold, it will recommend the Pizza recipe
mondico = {}
mondico["Tomate"] = 0
mondico["Farine"] = 0
mondico["Fromage"] = 0
#I copy and paste this as many times as I need for about 20 ingrediants
在下面,我有:
import tkinter as tk
window=tk.Tk()
window.geometry("900x900")
window.minsize(height=900 , width=900)
window.config(background='#B8FAEF')
frame=tk.Frame(window, bg='#B8FAEF')
label_title = tk.Label(window, text="SmartFridgoo", font=("Comic Sans MS", 20))
label_title.pack()
label_subtitle = tk.Label(window, text="Veuillez entrez vos ingrédients", font=("Comic Sans MS", 10))
label_subtitle.pack()
frame.pack(expand=1)
Texttomate=tk.Label(window,text="Tomates",)
Texttomate.pack()
saisirtomate=tk.IntVar()
saisietomate=tk.Entry(textvariable=saisirtomate, width=9, justify='center')
saisietomate.pack()
#I copy and paste this, you get the idea
bouton=tk.Button(window,text="Confirmer et faire apparaître les recettes", command=takequantity)
bouton.pack()
can=tk.Canvas(window, bg='#B8FAEF', height=400, width=600)
can.pack()
window.mainloop()
我想要的是,你放数字的插槽不会堆叠在一起,并像那样对齐。网格队形很好,但我不知道怎么做。 我还想让配方显示在画布的中心,但如果有多个配方,我希望它们排列整齐,而不是相互重叠。我该怎么做
如果我做错了什么,我向你道歉,这是我在这里的第一篇帖子
编辑:我也想能够把一个链接附加到文本显示。例如,当你点击“比萨饼”时,它会将你重定向到youtube菜谱。我查看了如何使用.bind进行绑定,但它不适用于“can.create_text”中的文本
在tkinter check effbot.org中,网格的形成非常容易。很酷的一点是,您可以在主窗口和框架内使用网格。例如,您可以创建一些框架并使用
widg.grid()
在其中插入小部件,然后也使用网格将框架放置在窗口中相关问题 更多 >
编程相关推荐