Problème clock python

Fermé
Extrayer Messages postés 1 Date d'inscription mardi 30 mai 2017 Statut Membre Dernière intervention 30 mai 2017 - 30 mai 2017 à 19:54
 gudu - 31 mai 2017 à 19:03
Bonjour,je veux créer une interface graphique , mais un problème est survenue sur mon script ma clock se lance apres avoir fermer ma fenêtre tkinter mais je voudrais que la clock et ma fenêtre tkinter s'ouvre en même temps

merci pour votre réponse

by

Mon script:

print ("|---------------------------------------------------------------|")
print ("| ExoLabe |")
print ("|---------------------------------------------------------------|")

from tkinter import *
from tkinter import colorchooser
import sys
import os
import time

main = Tk()
main.geometry("800x600+50+10")
main.resizable(width=False, height=False)
main.title("Exolabe")




interface = PhotoImage(file = "interface.png")
google1 = PhotoImage(file = "google.png")
paint1 = PhotoImage(file = "paint.png")
CCleaner1 = PhotoImage(file = "CCleaner.png")
py1 = PhotoImage(file = "py.png")
cmd1 = PhotoImage(file = "cmd.png")
minecraft1 = PhotoImage(file = "icon minecraft.png")

label1 = Label(main,image=interface).place(x='0',y='0')

def couleur():
color = colorchooser.askcolor()
color =str(color)
couleur1 = color.split("\'")
couleur2 = couleur1[1]
main['bg'] = couleur2


def Interface2():
main2 = Tk()
main2.geometry("800x600+50+10")
main2.resizable(width=False, height=False)
main2.title("Exolabe")
main.destroy()

def start_google():
os.startfile(r'chrome.exe')

def start_paint():
os.startfile(r'C:\Program Files\Paint.NET\PaintDotNet.exe')

def start_CCleaner():
os.startfile(r'C:\Program Files\CCleaner\CCleaner64.exe')

def start_py():
os.startfile(r'C:\Users\Marin\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.6\IDLE (Python 3.6 64-bit).lnk')

def start_google():
os.startfile(r'chrome.exe')

def start_cmd():
os.startfile(r'cmd.exe')

def start_minecraft():
os.startfile(r'C:\Program Files (x86)\Minecraft\Minecraft.exe')

def heure():
while n>0:
a = time.localtime()
print (a[3], a[4], a[5])
time.sleep(1)
Label(main,text=(a[3], a[4], a[5])).pack()



google = Button(main,command=start_google,width=50,height=50, image = google1)
google.place(x='25',y='300')

paint = Button(main,command=start_paint,width=50,height=50, image = paint1)
paint.place(x='25',y='225')

ccleaner = Button(main,command=start_CCleaner,width=50,height=50, image = CCleaner1)
ccleaner.place(x='25',y='375')

py = Button(main,command=start_py,width=50,height=50, image = py1)
py.place(x='25',y='450')

cmd = Button(main,command=start_cmd,width=50,height=50, image = cmd1)
cmd.place(x='25',y='525')

Minecraft = Button(main,command=start_minecraft,width=50,height=50, image = minecraft1)
Minecraft.place(x='25',y='150')




menu = Menu(main)
sousmenu = Menu(menu, tearoff=0)
menu.add_cascade(label="Menu", menu=sousmenu)
sousmenu.add_command(label="Google", command=start_google,image = google1)
sousmenu.add_command(label="Paint", command=start_google,image = paint1)
sousmenu.add_command(label="CCleaner", command=start_CCleaner,image = CCleaner1)
sousmenu.add_command(label="Python", command=start_py,image = py1)
sousmenu.add_command(label="Cmd", command=start_cmd,image = cmd1)

main.config(menu = menu)
n=1

main.mainloop()
heure()

1 réponse

Bon, ce serait bien d'utiliser les balises de mise en forme du code, c'est d’autant plus important en python.

En ce qui concerne ton problème, c'est que déjà ta fonction est derrière le mainloop, donc elle sera exécutée seulement lorsque ta fenêtre tkinter sera fermée.

Et on ne peut pas utiliser de sleep comme ça dans une application graphique, il faut que tu cherches ce qui concerne la méthode after de tkinter.
0