Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from time import sleep
- from threading import Thread
- class _timeout(Thread):
- def __init__(self, finestra):
- Thread.__init__(self)
- self.finestra = finestra
- def run(self):
- sleep(quandostop)
- self.finestra.destroy()
- finestra = None
- class msgbox:
- toret = 0
- def __init__(self,flag,titolo,mess,timeout = -1,bkground = 'default',pulswidth = 1,pulsbk = 'default',messcol = 'black',messbk = 'default'):
- global quandostop
- global finestra
- quandostop = timeout
- self.finestra = Tk()
- self.finestra.title(titolo)
- self.quadro1 = Frame(self.finestra)
- if bkground != 'default':
- self.quadro1["background"] = bkground
- self.quadro1.pack()
- self.label1 = Label(self.quadro1, text=mess)
- if messbk != 'default':
- self.label1["background"] = messbk
- self.label1["fg"] = messcol
- self.label1.pack()
- if str(flag) == '0': #ok
- self.puls1 = Button(self.quadro1)
- self.puls1["borderwidth"] = int(pulswidth)
- self.puls1["text"] = "Ok"
- if pulsbk != 'default':
- self.puls1["background"] = pulsbk
- self.puls1.pack()
- self.puls1.bind("<Button-1>", self.ok)
- if str(flag) == '1': #si no
- self.puls1 = Button(self.quadro1)
- self.puls1["borderwidth"] = int(pulswidth)
- self.puls1["text"] = "Si"
- if pulsbk != 'default':
- self.puls1["background"] = pulsbk
- self.puls1.pack(side = LEFT)
- self.puls1.bind("<Button-1>", self.si)
- self.puls2 = Button(self.quadro1)
- self.puls2["borderwidth"] = int(pulswidth)
- self.puls2["text"] = "No"
- if pulsbk != 'default':
- self.puls2["background"] = pulsbk
- self.puls2.pack(side = LEFT)
- self.puls2.bind("<Button-1>", self.no)
- if str(flag) == '2': #si no annulla
- self.puls1 = Button(self.quadro1)
- self.puls1["borderwidth"] = int(pulswidth)
- self.puls1["text"] = "Si"
- if pulsbk != 'default':
- self.puls1["background"] = pulsbk
- self.puls1.pack(side = LEFT)
- self.puls1.bind("<Button-1>", self.si)
- self.puls2 = Button(self.quadro1)
- self.puls2["borderwidth"] = int(pulswidth)
- self.puls2["text"] = "Annulla"
- if pulsbk != 'default':
- self.puls2["background"] = pulsbk
- self.puls2.pack(side = RIGHT)
- self.puls2.bind("<Button-1>", self.annulla)
- self.puls3 = Button(self.quadro1)
- self.puls3["borderwidth"] = int(pulswidth)
- self.puls3["text"] = "No"
- if pulsbk != 'default':
- self.puls3["background"] = pulsbk
- self.puls3.pack(side = RIGHT)
- self.puls3.bind("<Button-1>", self.no)
- if str(flag) == '3': #ok annulla
- self.puls1 = Button(self.quadro1)
- self.puls1["borderwidth"] = int(pulswidth)
- self.puls1["text"] = "Ok"
- if pulsbk != 'default':
- self.puls1["background"] = pulsbk
- self.puls1.pack(side = LEFT)
- self.puls1.bind("<Button-1>", self.ok)
- self.puls2 = Button(self.quadro1)
- self.puls2["borderwidth"] = int(pulswidth)
- self.puls2["text"] = "Annulla"
- if pulsbk != 'default':
- self.puls2["background"] = pulsbk
- self.puls2.pack(side = RIGHT)
- self.puls2.bind("<Button-1>", self.annulla)
- if str(flag) == '4': #annulla riprova ignora
- self.puls1 = Button(self.quadro1)
- self.puls1["borderwidth"] = int(pulswidth)
- self.puls1["text"] = "Riprova"
- if pulsbk != 'default':
- self.puls1["background"] = pulsbk
- self.puls1.pack(side = LEFT)
- self.puls1.bind("<Button-1>", self.riprova)
- self.puls2 = Button(self.quadro1)
- self.puls2["borderwidth"] = int(pulswidth)
- self.puls2["text"] = "Ignora"
- if pulsbk != 'default':
- self.puls2["background"] = pulsbk
- self.puls2.pack(side = LEFT)
- self.puls2.bind("<Button-1>", self.ignora)
- self.puls3 = Button(self.quadro1)
- self.puls3["borderwidth"] = int(pulswidth)
- self.puls3["text"] = "Annulla"
- if pulsbk != 'default':
- self.puls3["background"] = pulsbk
- self.puls3.pack(side = RIGHT)
- self.puls3.bind("<Button-1>", self.annulla)
- if str(flag) == '5': #riprova annulla
- self.puls1 = Button(self.quadro1)
- self.puls1["borderwidth"] = int(pulswidth)
- self.puls1["text"] = "Riprova"
- if pulsbk != 'default':
- self.puls1["background"] = pulsbk
- self.puls1.pack(side = LEFT)
- self.puls1.bind("<Button-1>", self.riprova)
- self.puls2 = Button(self.quadro1)
- self.puls2["borderwidth"] = int(pulswidth)
- self.puls2["text"] = "Annulla"
- if pulsbk != 'default':
- self.puls2["background"] = pulsbk
- self.puls2.pack(side = RIGHT)
- self.puls2.bind("<Button-1>", self.annulla)
- if str(flag) == '6': #annulla riprova continua
- self.puls1 = Button(self.quadro1)
- self.puls1["borderwidth"] = int(pulswidth)
- self.puls1["text"] = "Continua"
- if pulsbk != 'default':
- self.puls1["background"] = pulsbk
- self.puls1.pack(side = LEFT)
- self.puls1.bind("<Button-1>", self.continua)
- self.puls2 = Button(self.quadro1)
- self.puls2["borderwidth"] = int(pulswidth)
- self.puls2["text"] = "Riprova"
- if pulsbk != 'default':
- self.puls2["background"] = pulsbk
- self.puls2.pack(side = LEFT)
- self.puls2.bind("<Button-1>", self.riprova)
- self.puls3 = Button(self.quadro1)
- self.puls3["borderwidth"] = int(pulswidth)
- self.puls3["text"] = "Annulla"
- if pulsbk != 'default':
- self.puls3["background"] = pulsbk
- self.puls3.pack(side = RIGHT)
- self.puls3.bind("<Button-1>", self.annulla)
- if timeout != -1:
- my_thread = _timeout(self.finestra)
- my_thread.start()
- self.finestra.mainloop()
- def ok(self, evento):
- self.finestra.destroy()
- self.toret = 1
- def si(self, evento):
- self.finestra.destroy()
- self.toret = 2
- def no(self, evento):
- self.finestra.destroy()
- self.toret = 3
- def annulla(self, evento):
- self.finestra.destroy()
- self.toret = 4
- def riprova(self, evento):
- self.finestra.destroy()
- self.toret = 5
- def ignora(self, evento):
- self.finestra.destroy()
- self.toret = 6
- def continua(self, evento):
- self.finestra.destroy()
- self.toret = 7
- def get_ret_code(self):
- return self.toret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement