tk_popup.py 1.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
"""
    Shows a message popup using Tkinter window.
    
    Name: tk_popup.py
    Author: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
"""

import sys
if sys.version_info[0] < 3:
    import Tkinter as Tk
else:
    import tkinter as Tk
    
import thread

class Popup(object):
    
    
    def __init__(self, parent):
        self.parent = parent
        
    def _blocking_popup(self, message, width, height, title = 'Popup'):
        if message is None:
            return 
        
        self.root = Tk.Tk()
        self.root.title(title)
        self.root.geometry('%dx%d+%d+%d' % (width, height, 0, 0))
        text = Tk.Text(self.root, bg="white", fg="black", padx=5, pady=5)
        text.insert(Tk.INSERT, message)
        #text.configure(state='disabled')
        text.pack(side=Tk.TOP, fill=Tk.BOTH, expand=True)
        self.root.mainloop()
        
    def show(self, message, width=800, height=600):
        thread.start_new_thread(self._blocking_popup, (message, width, height))