以下是我当前的代码以及迄今为止我对以前版本所做的更改
- 我在开始时重置了变量,因为我不希望每次执行函数时都重置它们
- 我为过程的入口添加了一个ess_e变量,我希望这个变量存储函数执行时的本地时间
- 我添加了一个ess_s变量,用于在输入所有信息后退出过程,当按下提交按钮(更改后的文本(时,该变量应该是本地时间
剩下的问题是
-
root.bind不起作用,正如你所建议的,我已经尝试了几种fenetre的替代方案,但我无法使其起作用。
-
我在运行第二个函数(essenseresult(时出错
文件";D: \官僚主义\ Python \脚本\接口测试.py",第57行,本质结果ess_e=ent0.get((AttributeError:"datetime.datetime"对象没有属性"get">
我仍然需要制作框架来显示以前的结果,但我会在适当的时候到达:(
非常感谢的帮助
from tkinter import *
from datetime import *
import time
ess=[[],[],[],[],[]]
rel=[[],[],[],[],[]]
c60=[[],[]]
def c60duree(delta):
(h, r) = divmod(delta.seconds, 3600)
(m, s) = divmod(r, 60)
return "%s%02d:%02d:%02d" % (
"%d jour(s) " % delta.days if delta.days > 0 else "",
h,
m,
s,
)
def code60():
saisie=0
while saisie != "X":
c60d=datetime.now()
print ("Code 60 activé à ", c60d.strftime("%H:%M:%S"))
saisie=input("Tapez entree pour la fin du code 60, X pour sortir : ")
c60f=datetime.now()
print("Debut ", c60d.strftime("%H:%M:%S"))
print("Fin ", c60f.strftime("%H:%M:%S"))
c60x=c60f-c60d
print("Duree ", c60duree(c60x))
print("-------------")
c60[0].append(c60d)
c60[1].append(c60f)
#del(c60[0],[-1])
#del(c60[1],[-1])
#return
def relais():
print("Relais pilote demarré ")
relh=datetime.now()
relv=input("Quelle voiture ? ")
relp=input("Quel pilote repart ? ")
rele=input("Quantité d'essence ? ")
input("Tapez entrée à la sortie des stands ")
rels=datetime.now()
rel[0].append(relh), rel[1].append(relv), rel[2].append(relp), rel[3].append(rele), rel[4].append(rels)
print("Dureé ", rels-relh)
print(*rel)
#def essence():
#ess=[[],[],[],[]]
#print("Ravitaillement essence demarré ")
#essh=datetime.now()
#essv=input("Quelle voiture ? ")
#essp=input("Quel pilote ? ")
#essq=input("Combien de litres ? ")
#ess[0].append(essh), ess[1].append(essv), ess[2].append(essp), ess[3].append(essq)
#print(*ess)
def essenceResult(ess, ent0, ent1, ent2, ent3):
ess_e = ent0.get()
essv = ent1.get()
essp = ent2.get()
essq = ent3.get()
ess_s = datetime.now()
ess[0].append(ess_e), ess[1].append(essv), ess[2].append(essp), ess[3].append(essq), ess [4].append(ess_s)
resultLabel = Label(Frame4, text = str(*ess))
resultLabel.grid(row = 5, column = 0, columnspan = 2)
def essence():
print("yr")
ess_e=datetime.now()
Frame4.grid(row = 1, column = 0)
Label1 = Label(Frame4, text = "Ravitaillement demarré ")
Label1.grid(row = 0, column = 0, columnspan = 2)
essvLabel = Label(Frame4, text = "Quelle voiture ? ")
essvEntry = Entry(Frame4)
essvLabel.grid(row = 1, column = 0)
essvEntry.grid(row = 1, column = 1)
essvEntry.focus()
#root.bind_all("<Return>", function)
esspLabel = Label(Frame4, text = "Quel pilote part ? ")
esspEntry = Entry(Frame4)
esspLabel.grid(row = 2, column = 0)
esspEntry.grid(row = 2, column = 1)
esspEntry.focus()
essqLabel = Label(Frame4, text = "Combien de litres ? ")
essqEntry = Entry(Frame4)
essqLabel.grid(row = 3, column = 0)
essqEntry.grid(row = 3, column = 1)
essqEntry.focus()
submitButton = Button(Frame4, text = "Sortie des stands", command = lambda: essenceResult(ess, ess_e, essvEntry, esspEntry, essqEntry))
submitButton.grid(row = 4, column = 0, columnspan = 2)
fenetre = Tk()
fenetre['bg']='grey'
# frame 1
Frame1 = Frame(fenetre, bg="green", borderwidth=1, relief=GROOVE)
Frame1.grid(row = 0, column = 0, padx=5, pady=5)
# frame 2
Frame2 = Frame(fenetre, bg="yellow", borderwidth=1, relief=GROOVE)
Frame2.grid(row = 0, column = 1, padx=5, pady=5)
# frame 3
Frame3 = Frame(fenetre, bg="purple", borderwidth=1, relief=GROOVE)
Frame3.grid(row = 0, column = 2, padx=5, pady=5)
Frame4 = Frame(fenetre)
Fenetre = Tk()
fenetre['bg']='grey'
# Ajout de labels
Button(Frame1, text="Essence", command=essence).pack(padx=300, pady=100)
Button(Frame2, text="Relais", command=relais).pack(padx=300, pady=100)
Button(Frame3, text="Code 60", command=code60).pack(padx=300, pady=100)
以下是固定代码:
def essenceResult(ess, ess_e, ent1, ent2, ent3):
essv = ent1.get()
essp = ent2.get()
essq = ent3.get()
ess_s = datetime.now()
ess[0].append(ess_e), ess[1].append(essv), ess[2].append(essp), ess[3].append(essq), ess[4].append(ess_s)
resultLabel = Label(Frame4, text = str(ess))
resultLabel.grid(row = 5, column = 0, columnspan = 2)
def essence():
print("yr")
ess_e=datetime.now()
Frame4.grid(row = 1, column = 0)
Label1 = Label(Frame4, text = "Ravitaillement demarré ")
Label1.grid(row = 0, column = 0, columnspan = 2)
essvLabel = Label(Frame4, text = "Quelle voiture ? ")
essvEntry = Entry(Frame4)
essvLabel.grid(row = 1, column = 0)
essvEntry.grid(row = 1, column = 1)
essvEntry.focus()
esspLabel = Label(Frame4, text = "Quel pilote part ? ")
esspEntry = Entry(Frame4)
esspLabel.grid(row = 2, column = 0)
esspEntry.grid(row = 2, column = 1)
esspEntry.focus()
essqLabel = Label(Frame4, text = "Combien de litres ? ")
essqEntry = Entry(Frame4)
essqLabel.grid(row = 3, column = 0)
essqEntry.grid(row = 3, column = 1)
essqEntry.focus()
submitCommand = lambda event = None: essenceResult(ess, ess_e, essvEntry, esspEntry, essqEntry)
submitButton = Button(Frame4, text = "Sortie des stands", command = submitCommand)
Frame4.bind_all("<Return>", submitCommand)
submitButton.grid(row = 4, column = 0, columnspan = 2)
您还需要删除Frame4
之后的额外Fenetre = Tk()
,因为这会破坏它。(如果您想要更多的窗口使用Toplevel()
,则只能有一个Tk()
(
添加Frame4.bind_all("<Return>", submitCommand)
可以解决第一个问题。现在,当您按下回车键时,它将运行submitCommand
,也就是运行essenceResult
第二个问题是在datetime.datetime
对象上使用.get()
。不能使用.get()
,因为它不是一个条目。相反,只需将其作为一个参数,不要更改它。您只需要.get()
就可以从Tkinter条目中获取值。