Q1: 11 класс по информатике.Меня попросили создать полезное настольное приложение.То, что пришло мне в голову, было меню ресторана.Меню содержит около 150 ярлыков и 100 кнопок.Для 100 кнопок 50 из них имеют аналогичную функцию: добавить блюдо, а 50 из них имеют противоположную функцию: удалить блюдо.Поэтому я хочу попробовать использовать только 2 функции для выполнения 100 функций, поскольку я действительно не хочу создавать 100 функций.Q2: есть ли способ найти текущий кадр, на котором находится пользователь ноутбука?
from tkinter import *
from tkinter import ttk
from Tkinter import Widget
def add():
pass
def subtra():
pass
root = Tk()
style = ttk.Style(root)
style.configure('lefttab.TNotebook', tabposition='wn')
# Menu
menu = ttk.Notebook(root, style='lefttab.TNotebook')
catename=[" Appetizer ", " Soup ", " Rice ", " Noodle ", " Duck ", " Pork ", " Beef ", " Chicken ", " KingPrawn ", "Scallop and Sea food", " Vegetables ", " Dessert ", " Beverage "]
cate=[]
#Creat
for i in range(0, len(catename)):
cate.append(Frame(menu, bg="white", width=1000, height=1000))
#Grid
for i in range(0, len(catename)):
menu.add(cate[i], text=catename[i])
#End of Menu
# Dish names
DishName=[
["Egg Rol","Mini Spring Rolls","Vegetarian Spring Rolls","Thai Rolls"],
["Clear Consume Soup","Chicken Egg Drop Soup","Wonton & B.B.Q. Pork Soup","Chicken & Sweet Corn Soup"],
["Steamed Rice","Vegetable Fried Rice","Mushroom Fried Rice","Chicken Fried Rice"],
["Singapore Vermicelli Noodle","Shanghai Thick Noodle","Beef Flat Noodle","Chicken Flat Noodle"],
["Old Fashion Braised Duck","B.B.Q. Roasted Duck (Half)","Duck Lettuce Wrap","Shredded Duck Meat in Szechuan Sauce"],
["B.B.Q Pork Chop Suey","B.B.Q. Pork Chow Mein","B.B.Q. Pork Egg Foo Young","B.B.Q. Pork with Seasonal Vegetables"],
["Beef Chop Suey","Beef Chow Mein","Beef Egg Foo Young","Beef with Seasonal Vegetables"],
["Chicken Chop Suey","Chicken Chow Mein","Chicken Egg Foo Young","Chicken with Seasonal Vegetables"],
["King Prawn with Vegetables","King Prawn in Curry Sauce","King Prawn in Black Bean Sauce","King Prawn in Satay Sauce"],
["Scallop with Vegetables","Scallop in Black Bean Sauce","Sea Salt Scallop","Live Lobster"],
["Mixed Vegetables","Spicy Egg Plant","Spicy Bean Stalk","Buddha Delight"],
["Home Made Almond Cookie","Cake of the Day","Fresh Lychee Fruit","Mandarin Cheese Cake"],
["Coke","Sprite","Diet Coke","Gingerale"]
]
Dishlables=[]
#Creat
for i in range(0, len(catename)):
singlepage=[]
for j in range(0, 4):
singlepage.append(Label(cate[i],text=DishName[i][j]))
Dishlables.append(singlepage)
#Grid
for i in range(0, len(catename)):
for j in range(0, 4):
Dishlables[i][j].grid(column=1,row=j+1,sticky=W)
#Dish Prices
DishPrice=[[2.25,5.25,5.25,7.50],
[4.50,5.50,5.50,5.50],
[3.25,7.95,8.50,8,50],
[13.25,13.95,13.95,13.95],
[19.95,20.95,55.00,55.00],
[9.95,10.50,11.95,12.50],
[10.95,11.50,12.50,13.50],
[9.95,10.50,11.95,13.50],
[18.95,18.95,18.95,18.95],
[19.95,19.95,20.95,12.95],
[9.95,10.95,11.25,12.95],
[3.50,5.95,5.95,6.50],
[1.75,1.75,1.75,1.75],
]
Pricelables=[]
#Creat
for i in range(0, len(catename)):
singlepage=[]
for j in range(0, 4):
singlepage.append(Label(cate[i],text=f'{DishPrice[i][j]:.2f}'))
Pricelables.append(singlepage)
#Grid
for i in range(0, len(catename)):
for j in range(0, 4):
Pricelables[i][j].grid(column=2,row=j+1,sticky=W)
#Number of servings ordered
Count=[]
single=[0,0,0,0]
for i in range(0, len(catename)):
for j in range(0,4):
Count.append(single)
countlables=[]
#Creat
for i in range(0, len(catename)):
single=[]
for j in range(0,4):
single.append( Label(cate[i], text=f'{Count[i][j]}'))
countlables.append(single)
print(Count[0][0])
#Grid
for i in range(0, len(catename)):
for j in range(0,4):
countlables[i][j].grid(column=4, row=j+1,sticky=E)
#Add Button
Buttonsadd=[]
#Creat
for i in range(0, len(catename)):
single=[]
for j in range(0, 4):
single.append(Button(cate[i], text="+",command=add))
Buttonsadd.append(single)
#Grid
for i in range (0, len(catename)):
for j in range(0, 4):
Buttonsadd[i][j].grid(column=5,row=j+1)
#Minus Button
Buttonsminus=[]
#Creat
for i in range(0, len(catename)):
single=[]
for j in range(0, 4):
single.append(Button(cate[i], text="-",command=subtra))
Buttonsminus.append(single)
#Grid
for i in range (0, len(catename)):
for j in range(0, 4):
Buttonsminus[i][j].grid(column=3,row=j+1)
menu.pack()
root.mainloop()