Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.06 KB | None | 0 0
  1. from tkinter import *
  2. from time import sleep
  3. from threading import Thread
  4.  
  5.  
  6. class _timeout(Thread):
  7.     def __init__(self, finestra):
  8.         Thread.__init__(self)
  9.         self.finestra = finestra
  10.  
  11.     def run(self):
  12.         sleep(quandostop)
  13.         self.finestra.destroy()
  14.        
  15. finestra = None
  16.  
  17. class msgbox:
  18.  
  19.     toret = 0
  20.    
  21.     def __init__(self,flag,titolo,mess,timeout = -1,bkground = 'default',pulswidth = 1,pulsbk = 'default',messcol = 'black',messbk = 'default'):
  22.         global quandostop
  23.         global finestra
  24.         quandostop = timeout
  25.         self.finestra = Tk()                              
  26.         self.finestra.title(titolo)                  
  27.         self.quadro1 = Frame(self.finestra)
  28.         if bkground != 'default':
  29.             self.quadro1["background"] = bkground
  30.         self.quadro1.pack()
  31.         self.label1 = Label(self.quadro1, text=mess)
  32.         if messbk != 'default':
  33.             self.label1["background"] = messbk
  34.             self.label1["fg"] = messcol
  35.         self.label1.pack()
  36.         if str(flag) == '0': #ok
  37.             self.puls1 = Button(self.quadro1)                      
  38.             self.puls1["borderwidth"] = int(pulswidth)                    
  39.             self.puls1["text"] = "Ok"  
  40.             if pulsbk != 'default':
  41.                 self.puls1["background"] = pulsbk              
  42.             self.puls1.pack()
  43.             self.puls1.bind("<Button-1>", self.ok)
  44.  
  45.         if str(flag) == '1': #si no
  46.             self.puls1 = Button(self.quadro1)                      
  47.             self.puls1["borderwidth"] = int(pulswidth)                    
  48.             self.puls1["text"] = "Si"
  49.             if pulsbk != 'default':
  50.                 self.puls1["background"] = pulsbk              
  51.             self.puls1.pack(side = LEFT)
  52.             self.puls1.bind("<Button-1>", self.si)
  53.             self.puls2 = Button(self.quadro1)                      
  54.             self.puls2["borderwidth"] = int(pulswidth)                    
  55.             self.puls2["text"] = "No"  
  56.             if pulsbk != 'default':
  57.                 self.puls2["background"] = pulsbk              
  58.             self.puls2.pack(side = LEFT)
  59.             self.puls2.bind("<Button-1>", self.no)
  60.  
  61.         if str(flag) == '2': #si no annulla
  62.             self.puls1 = Button(self.quadro1)                      
  63.             self.puls1["borderwidth"] = int(pulswidth)                    
  64.             self.puls1["text"] = "Si"  
  65.             if pulsbk != 'default':
  66.                 self.puls1["background"] = pulsbk              
  67.             self.puls1.pack(side = LEFT)
  68.             self.puls1.bind("<Button-1>", self.si)
  69.             self.puls2 = Button(self.quadro1)                      
  70.             self.puls2["borderwidth"] = int(pulswidth)                    
  71.             self.puls2["text"] = "Annulla"  
  72.             if pulsbk != 'default':
  73.                 self.puls2["background"] = pulsbk              
  74.             self.puls2.pack(side = RIGHT)
  75.             self.puls2.bind("<Button-1>", self.annulla)
  76.             self.puls3 = Button(self.quadro1)                      
  77.             self.puls3["borderwidth"] = int(pulswidth)                    
  78.             self.puls3["text"] = "No"  
  79.             if pulsbk != 'default':
  80.                 self.puls3["background"] = pulsbk              
  81.             self.puls3.pack(side = RIGHT)
  82.             self.puls3.bind("<Button-1>", self.no)
  83.  
  84.         if str(flag) == '3': #ok annulla
  85.             self.puls1 = Button(self.quadro1)                      
  86.             self.puls1["borderwidth"] = int(pulswidth)                    
  87.             self.puls1["text"] = "Ok"  
  88.             if pulsbk != 'default':
  89.                 self.puls1["background"] = pulsbk              
  90.             self.puls1.pack(side = LEFT)
  91.             self.puls1.bind("<Button-1>", self.ok)
  92.             self.puls2 = Button(self.quadro1)                      
  93.             self.puls2["borderwidth"] = int(pulswidth)                    
  94.             self.puls2["text"] = "Annulla"  
  95.             if pulsbk != 'default':
  96.                 self.puls2["background"] = pulsbk              
  97.             self.puls2.pack(side = RIGHT)
  98.             self.puls2.bind("<Button-1>", self.annulla)
  99.  
  100.         if str(flag) == '4': #annulla riprova ignora
  101.             self.puls1 = Button(self.quadro1)                      
  102.             self.puls1["borderwidth"] = int(pulswidth)                    
  103.             self.puls1["text"] = "Riprova"  
  104.             if pulsbk != 'default':
  105.                 self.puls1["background"] = pulsbk              
  106.             self.puls1.pack(side = LEFT)
  107.             self.puls1.bind("<Button-1>", self.riprova)
  108.             self.puls2 = Button(self.quadro1)                      
  109.             self.puls2["borderwidth"] = int(pulswidth)                    
  110.             self.puls2["text"] = "Ignora"  
  111.             if pulsbk != 'default':
  112.                 self.puls2["background"] = pulsbk              
  113.             self.puls2.pack(side = LEFT)
  114.             self.puls2.bind("<Button-1>", self.ignora)
  115.             self.puls3 = Button(self.quadro1)                      
  116.             self.puls3["borderwidth"] = int(pulswidth)                    
  117.             self.puls3["text"] = "Annulla"  
  118.             if pulsbk != 'default':
  119.                 self.puls3["background"] = pulsbk              
  120.             self.puls3.pack(side = RIGHT)
  121.             self.puls3.bind("<Button-1>", self.annulla)
  122.  
  123.         if str(flag) == '5': #riprova annulla
  124.             self.puls1 = Button(self.quadro1)                      
  125.             self.puls1["borderwidth"] = int(pulswidth)                    
  126.             self.puls1["text"] = "Riprova"  
  127.             if pulsbk != 'default':
  128.                 self.puls1["background"] = pulsbk              
  129.             self.puls1.pack(side = LEFT)
  130.             self.puls1.bind("<Button-1>", self.riprova)
  131.             self.puls2 = Button(self.quadro1)                      
  132.             self.puls2["borderwidth"] = int(pulswidth)                    
  133.             self.puls2["text"] = "Annulla"  
  134.             if pulsbk != 'default':
  135.                 self.puls2["background"] = pulsbk              
  136.             self.puls2.pack(side = RIGHT)
  137.             self.puls2.bind("<Button-1>", self.annulla)
  138.  
  139.         if str(flag) == '6': #annulla riprova continua
  140.             self.puls1 = Button(self.quadro1)                      
  141.             self.puls1["borderwidth"] = int(pulswidth)                    
  142.             self.puls1["text"] = "Continua"  
  143.             if pulsbk != 'default':
  144.                 self.puls1["background"] = pulsbk              
  145.             self.puls1.pack(side = LEFT)
  146.             self.puls1.bind("<Button-1>", self.continua)
  147.             self.puls2 = Button(self.quadro1)                      
  148.             self.puls2["borderwidth"] = int(pulswidth)                    
  149.             self.puls2["text"] = "Riprova"  
  150.             if pulsbk != 'default':
  151.                 self.puls2["background"] = pulsbk              
  152.             self.puls2.pack(side = LEFT)
  153.             self.puls2.bind("<Button-1>", self.riprova)
  154.             self.puls3 = Button(self.quadro1)                      
  155.             self.puls3["borderwidth"] = int(pulswidth)                    
  156.             self.puls3["text"] = "Annulla"  
  157.             if pulsbk != 'default':
  158.                 self.puls3["background"] = pulsbk              
  159.             self.puls3.pack(side = RIGHT)
  160.             self.puls3.bind("<Button-1>", self.annulla)
  161.  
  162.         if timeout != -1:
  163.             my_thread = _timeout(self.finestra)
  164.             my_thread.start()
  165.         self.finestra.mainloop()
  166.  
  167.     def ok(self, evento):
  168.         self.finestra.destroy()
  169.         self.toret = 1
  170.  
  171.     def si(self, evento):
  172.         self.finestra.destroy()
  173.         self.toret = 2
  174.  
  175.     def no(self, evento):
  176.         self.finestra.destroy()
  177.         self.toret = 3
  178.  
  179.     def annulla(self, evento):
  180.         self.finestra.destroy()
  181.         self.toret = 4
  182.  
  183.     def riprova(self, evento):
  184.         self.finestra.destroy()
  185.         self.toret = 5
  186.  
  187.     def ignora(self, evento):
  188.         self.finestra.destroy()
  189.         self.toret = 6
  190.  
  191.     def continua(self, evento):
  192.         self.finestra.destroy()
  193.         self.toret = 7
  194.  
  195.     def get_ret_code(self):
  196.         return self.toret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement