【发布时间】:2017-09-03 18:48:18
【问题描述】:
所以我一直在研究这个程序,我发现很难找出问题所在。我对 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 的新手,所以如果我已经看过它,我还没有想出如何实现它。
【问题讨论】:
-
最后,我要做的是确保颜色根据条目变为绿色、红色、黄色。
标签: python-3.x tkinter background-color tkinter-entry