最近在工作中,我编写了一个简短的应用程序来将数据保存在Excel中。仅在不小心按下按钮后出现问题,在输入参数之前先进行确认。然后,空字段保留在工作表中。我知道如何设置按钮活动。我无法创建一种情况,当输入参数时,python“监听”并不断检查条件是否正确。
import datetime, time
from tkinter import *
from tkinter import ttk, Entry
from openpyxl import load_workbook
import winsound
from infi.systray import SysTrayIcon
import os
from tkinter import messagebox
def okno_wprowadzania_1():
global temp, day, TiMes, m_Y, wiersz, wilg, master, list, pytanie
while True:
TiMe = datetime.datetime.now()
TiMes = TiMe.strftime("%H:%M")
if (TiMes == '07:00') or (TiMes == '07:10') or (TiMes == '07:20'):
wiersz = 7
day = TiMe.strftime("%d")
break
if (TiMes == '10:30') or (TiMes == '10:45') or (TiMes == '11:00'):
wiersz = 11
day = TiMe.strftime("%d")
break
if (TiMes == '14:30') or (TiMes == '14:45') or (TiMes == '15:00'):
wiersz = 15
day = TiMe.strftime("%d")
break
if (TiMes == '18:30') or (TiMes == '18:45') or (TiMes == '19:00'):
wiersz = 19
day = TiMe.strftime("%d")
break
if (TiMes == '22:30') or (TiMes == '22:45') or (TiMes == '23:00'):
wiersz = 23
day = TiMe.strftime("%d")
break
if (TiMes == '02:30') or (TiMes == '02:45') or (TiMes == '03:00'):
wiersz = 27
day = TiMe.strftime("%d")
print(day)
korekta = int(day) - 1
day = korekta
print(day)
break
master=Tk()
master.protocol("WM_DELETE_WINDOW", on_closing)
master.title('Wpisz parametry')
nazwisko=Label(master,text='Pracownik',bg='yellow green')
nazwisko.pack(fill=X)
list = Listbox(master,width=40,height=3)
list.pack(fill=X)
list.insert(END)
for item in ['A','M','G']:
list.insert(END,item)
temperatura=Label(master,text='Temperatura',bg='yellow green')
temperatura.pack(fill=X)
temp=Entry(master)
temp.pack(fill=X)
wilgotnosc=Label(master,text='Wilgotność',bg='yellow green')
wilgotnosc.pack(fill=X)
wilg=Entry(master)
wilg.pack(fill=X)
zamknij=Button(master,text="Zapisz",command=master.quit)
zamknij.pack(fill=X)
def answer1():
answer1 = wilg.get()
return answer1
if answer1=='':
zamknij.configure(state='disabled')
else:
zamknij.configure(state='normal')
总结:如果输入字段为空,则该按钮处于非活动状态,输入参数后,该按钮应处于活动状态。 该怎么做?