所以我一直在研究这个程序,但我发现很难找出问题所在。我对 tkinter 还很陌生,所以这可能很小。
我试图让程序在按下复选按钮时更改输入框的背景颜色。或者更好的是,如果我可以动态地改变它,那就更好了。
这是我目前的代码:
TodayReading = []
colour = ""
colourselection= ['green3', 'dark orange', "red3"]
count = 0
def MakeForm(root, fields):
entries = []
for field in fields:
row = Frame(root)
lab = Label(row, width=15, text=field, font=("Device",10, "bold"), anchor='center')
ent = Entry(row)
row.pack(side=TOP, padx=5, fill=X, pady=5)
lab.pack(side=LEFT)
ent.pack(side=RIGHT, expand=YES, fill=X)
entries.append((field, ent))
return entries
def SaveData(entries):
import time
for entry in entries:
raw_data_point = entry[1].get()
data_point = (str(raw_data_point))
TodayReading.append(data_point)
c.execute("CREATE TABLE IF NOT EXISTS RawData (Date TEXT, Glucose REAL, BP INTEGER, Weight INTEGER)")
c.execute("INSERT INTO RawData (Date, Glucose, BP, Weight) VALUES (?, ?, ?, ?)", (time.strftime("%d/%m/%Y"), TodayReading[0], TodayReading[1] , TodayReading[2]))
conn.commit()
conn.close()
def DataCheck():
if ((float(TodayReading[0])>=4 and (float(TodayReading[0])<=6.9))):
colour = colourselection[count]
NAME OF ENTRY BOX HERE.configure(bg=colour)
谢谢您的帮助。有人可能已经回答了,但就像我说的,我是 tkinter 的新手,所以如果我已经看过它,我还没有弄清楚如何实现它。