tk_customframe.py 1.91 KB
Newer Older
1 2 3 4
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
"""
5 6 7 8
    Provides customized grids extending Tkinter.Frame.
    
    Name: tk_customframe.py
    Author: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
9
"""
10

11 12 13 14 15 16
import sys
if sys.version_info[0] < 3:
    import Tkinter as Tk
else:
    import tkinter as Tk

17 18
from tk_utils import Utils
from util.x11_colors import X11Colors
19

20 21 22 23 24 25 26 27 28 29 30
class CustomGrid(Tk.Frame):

    
    def __init__(self, parent, width = 0, height = 0, bg='white'):
        self.parent = parent
        
        self.v = Tk.IntVar()
        
        Tk.Frame.__init__(self, self.parent, width=width, height=height, bg=bg)


31
    
32 33 34 35
    def add_cell_label(self, text, row, column, width=0, height=0, bg='white', fg="black"):
        
        Tk.Label(self, text=text, width=width, height=height, bg=bg, fg=fg, padx=4, pady=4).grid(row=row, column=column)
        
36
    
37 38
    def add_cell_button_color(self, text, row, column, width=0, height=0, bg='white', fg="black", command=None, command_args=None):
        
39
        bg_color = X11Colors.get_color_hex(bg)
40
        
41 42 43
        bt = Tk.Button(self, text=text, width=width, height=height, bg=bg_color, fg=fg, padx=0, pady=0, cursor="hand1",
                    command=lambda *_: command(command_args))
        bt.grid(row=row, column=column)
44
        
45
    
46
    def add_cell_radio_button(self, text, value, row, column, width=0, height=0, bg='white', fg="black", selected=False, command=None, command_args=None):
47 48 49
        
        radio = Tk.Radiobutton(self, text=text, variable=self.v, value=value, 
                                width=width, height=height, bg=bg, fg=fg, padx=4, pady=4, 
50
                                indicatoron=1, anchor=Tk.W, command=lambda *_: command(command_args),
51 52 53 54 55 56 57
                                activebackground='#404040', highlightbackground='white')
        
        radio.grid(row=row, column=column)

        if(selected == True):
            radio.select()