我對 python 和 Tkinter 真的很陌生,但我正在嘗試制作

uj5u.com熱心網友回復:
你需要有與你的按鈕相關聯的命令,我使用部分將引數傳遞給函式。如果運行良好,請更新我。
from tkinter import *
from functools import partial
ws = Tk()
ws.title("Cleanliness Rater")
ws.geometry("500x500")
score = []
total_rating = 0
def calculate(x):
global score
score.append(x)
total_rating = sum(score)/len(score)
print(total_rating)
#Label2(ws, text="Please rate the cleanliness rating till now: " total_rating, font=("arial ", 12) ).pack()
Label(ws, text="Please rate the cleanliness of this bus: ", font=("arial ", 12) ).pack()
Label(ws, text="):", font=("arial ", 12) ).pack()
one = Button(ws,command = partial(calculate, 1), text="1", borderwidth=3, relief="raised", padx=5, pady=10).pack(padx=5, pady=10)
two = Button(ws,command = partial(calculate, 2), text="2", borderwidth=3, relief="raised", padx=5, pady=10).pack(padx=5, pady=10)
three = Button(ws,command = partial(calculate, 3), text="3", borderwidth=3, relief="raised", padx=5, pady=10).pack(padx=5, pady=10)
four = Button(ws,command = partial(calculate, 4), text="4", borderwidth=3, relief="raised", padx=5, pady=10).pack(padx=5, pady=10)
five = Button(ws,command = partial(calculate, 5), text="5", borderwidth=3, relief="raised", padx=5, pady=10).pack(padx=5, pady=10)
Label(ws, text="(:", font=("arial ", 12) ).pack()
ws.mainloop()
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/483745.html
上一篇:自定義tkinter標簽背景
