Python ttk.Style() Examples

The following are code examples for showing how to use ttk.Style(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.

Example 1
Project: Smart-Trader   Author: i-sultan   File: st_main_view.py    (license) View Source Project 11 votes vote down vote up
def set_app_style():
    style = ttk.Style()
    style.theme_create( "st_app", parent="alt", settings={
        ".":             {"configure": {"background"      : StColors.dark_grey,
                                        "foreground"      : StColors.light_grey,
                                        "relief"          : "flat",
                                        "highlightcolor"  : StColors.bright_green}},

        "TLabel":        {"configure": {"foreground"      : StColors.bright_green,
                                        "padding"         : 10,
                                        "font"            : ("Calibri", 12)}},

        "TNotebook":     {"configure": {"padding"         : 5}},
        "TNotebook.Tab": {"configure": {"padding"         : [25, 5], 
                                        "foreground"      : "white"},
                            "map"      : {"background"      : [("selected", StColors.mid_grey)],
                                        "expand"          : [("selected", [1, 1, 1, 0])]}},

        "TCombobox":     {"configure": {"selectbackground": StColors.dark_grey,
                                        "fieldbackground" : "white",
                                        "background"      : StColors.light_grey,
                                        "foreground"      : "black"}},

        "TButton":       {"configure": {"font"            :("Calibri", 13, 'bold'),
                                        "background"      : "black",
                                        "foreground"      : StColors.bright_green},
                            "map"      : {"background"      : [("active", StColors.bright_green)],
                                        "foreground"      : [("active", 'black')]}},
            
        "TEntry":        {"configure": {"foreground"      : "black"}},
        "Horizontal.TProgressbar":{"configure": {"background": StColors.mid_grey}}
    })
    style.theme_use("st_app")

#.----------------.
#|    classes     |
#'----------------' 
Example 2
Project: python2-tracer   Author: extremecoders-re   File: widget_state.py    (license) View Source Project 8 votes vote down vote up
def __init__(self, title=None):
        ttk.Frame.__init__(self, borderwidth=6)
        self.master.title(title)

        self.style = ttk.Style()

        # get default font size and family
        btn_font = self.style.lookup("TButton", "font")
        fsize = str(self.tk.eval("font configure %s -size" % btn_font))
        self.font_family = self.tk.eval("font configure %s -family" % btn_font)
        if ' ' in self.font_family:
            self.font_family = '{%s}' % self.font_family
        self.fsize_prefix = fsize[0] if fsize[0] == '-' else ''
        self.base_fsize = int(fsize[1 if fsize[0] == '-' else 0:])

        # a list to hold all the widgets that will have their states changed
        self.update_widgets = []

        self._setup_widgets() 
Example 3
Project: StochOPy   Author: keurfonluu   File: gui.py    (license) View Source Project 6 votes vote down vote up
def main():
    """
    Start StochOPy Viewer window.
    """
    import matplotlib
    matplotlib.use("TkAgg")
    from sys import platform as _platform
    
    root = tk.Tk()
    root.resizable(0, 0)
    StochOGUI(root)
    s = ttk.Style()
    if _platform == "win32":
        s.theme_use("vista")
    elif _platform in [ "linux", "linux2" ]:
        s.theme_use("alt")
    elif _platform == "darwin":
        s.theme_use("aqua")
    root.mainloop() 
Example 4
Project: image-copy-move-detection   Author: rahmatnazali   File: main_GUI.py    (license) View Source Project 6 votes vote down vote up
def initUI(self):
        self.parent.title("Image Copy-Move Detection")
        self.style = Style().configure("TFrame", background="#333")
        # self.style.theme_use("default")
        self.pack(fill=BOTH, expand=1)

        quitButton = Button(self, text="Open File", command=self.onFilePicker)
        quitButton.place(x=10, y=10)

        printButton = Button(self, text="Detect", command=self.onDetect)
        printButton.place(x=10, y=40)

        self.textBoxFile = Text(self, state='disabled', width=80, height = 1)
        self.textBoxFile.place(x=90, y=10)

        self.textBoxLog = Text(self, state='disabled', width=40, height=3)
        self.textBoxLog.place(x=90, y=40)

        # absolute image widget
        imageLeft = Image.open("resource/empty.png")
        imageLeftLabel = ImageTk.PhotoImage(imageLeft)
        self.labelLeft = Label(self, image=imageLeftLabel)
        self.labelLeft.image = imageLeftLabel
        self.labelLeft.place(x=5, y=100)

        imageRight = Image.open("resource/empty.png")
        imageRightLabel = ImageTk.PhotoImage(imageRight)
        self.labelRight = Label(self, image=imageRightLabel)
        self.labelRight.image = imageRightLabel
        self.labelRight.place(x=525, y=100)


        self.centerWindow() 
Example 5
Project: cablefish   Author: michgur   File: filter_hints.py    (license) View Source Project 6 votes vote down vote up
def __init__(self, root):
        tk.Frame.__init__(self, root, bg='#7F7F7F')

        ttk.Style().layout('Filter.Treeview', [
            ('Treeview.entry', {
                'border': '1', 'children':
                    [('Treeview.padding', {
                        'children':
                            [('Treeview.treearea', {'sticky': 'nswe'})], 'sticky': 'nswe'
                    })],
                'sticky': 'nswe'
            })
        ])

        self.frame = tk.Frame(self)
        self.tree = ttk.Treeview(self.frame, show='tree', style='Filter.Treeview')

        # for p in root.app.protocols:
        #     print p

            # fixme 
Example 6
Project: cablefish   Author: michgur   File: packets_list.py    (license) View Source Project 6 votes vote down vote up
def __init__(self, root):
        tk.Canvas.__init__(self, root, bg='#FEF9F4', highlightthickness=0)

        ttk.Style().layout('Packets.Treeview', [('Treeview.treearea', {'sticky': 'nswe'})])
        ttk.Style().configure('Packets.Treeview', foreground='#000000', background='#FEF9F4')

        self.packets = {}

        self.tree_frame = tk.Frame(self, bg='black')
        self.tree = ttk.Treeview(self.tree_frame, height=0, style='Packets.Treeview', show='headings')
        self.tree['columns'] = ['no', 'time', 'src', 'dst', 'protocol', 'length']
        cdata = [
            ('Index', False, 50, tk.E),
            ('Time', False, 100, tk.CENTER),
            ('Source', True, 120, tk.W),
            ('Destination', True, 120, tk.W),
            ('Protocol', True, 60, tk.CENTER),
            ('Length', False, 80, tk.E)
        ]
        self.size = 0
        for i, c in enumerate(cdata):
            cname = self.tree['columns'][i]
            self.tree.heading(cname, text=c[0])
            self.tree.column(cname, stretch=c[1], width=c[2], anchor=c[3])
        for i in range(12): self.tree.tag_configure('n%i' % i, background=colors_normal[i % 2])

        self.scroll = ttk.Scrollbar(self, style='Vertical.TScrollbar', orient=tk.VERTICAL, command=self.tree.yview)
        self.tree.configure(yscrollcommand=self.scroll.set)

        self.img = tk.PhotoImage(file='CF_back.gif').subsample(2, 2)
        self.background = self.create_image((350, 160), image=self.img, anchor=tk.CENTER)

        self.bind('<Configure>', self.recenter_bg)
        self.rb = False 
Example 7
Project: code   Author: ActiveState   File: recipe-580774.py    (MIT License) View Source Project 5 votes vote down vote up
def get_background_of_widget(widget):
    try:
        # We assume first tk widget
        background = widget.cget("background")
    except:
        # Otherwise this is a ttk widget
        style = widget.cget("style")

        if style == "":
            # if there is not style configuration option, default style is the same than widget class
            style = widget.winfo_class()

        background = Style().lookup(style, 'background')
    
    return background 
Example 8
Project: XimaExport   Author: ryankomodo   File: ximaexport-gui.py    (license) View Source Project 5 votes vote down vote up
def initUI(self):
        self.parent.title(self.title)
        self.style=Style()
        #Choose from default, clam, alt, classic
        self.style.theme_use('alt')
        self.pack(fill=tk.BOTH,expand=True)
        self.centerWindow() 
Example 9
Project: oil   Author: oilshell   File: test_style.py    (license) View Source Project 5 votes vote down vote up
def setUp(self):
        super(StyleTest, self).setUp()
        self.style = ttk.Style(self.root) 
Example 10
Project: python2-tracer   Author: extremecoders-re   File: combo_themes.py    (license) View Source Project 5 votes vote down vote up
def __init__(self):
        ttk.Frame.__init__(self)

        self.style = ttk.Style()
        self._setup_widgets() 
Example 11
Project: python2-tracer   Author: extremecoders-re   File: ttkcalendar.py    (license) View Source Project 5 votes vote down vote up
def __setup_styles(self):
        # custom ttk styles
        style = ttk.Style(self.master)
        arrow_layout = lambda dir: (
            [('Button.focus', {'children': [('Button.%sarrow' % dir, None)]})]
        )
        style.layout('L.TButton', arrow_layout('left'))
        style.layout('R.TButton', arrow_layout('right')) 
Example 12
Project: python2-tracer   Author: extremecoders-re   File: ttkcalendar.py    (license) View Source Project 5 votes vote down vote up
def test():
    import sys
    root = Tkinter.Tk()
    root.title('Ttk Calendar')
    ttkcal = Calendar(firstweekday=calendar.SUNDAY)
    ttkcal.pack(expand=1, fill='both')

    if 'win' not in sys.platform:
        style = ttk.Style()
        style.theme_use('clam')

    root.mainloop() 
Example 13
Project: ndk-python   Author: gittor   File: test_style.py    (license) View Source Project 5 votes vote down vote up
def setUp(self):
        self.style = ttk.Style() 
Example 14
Project: Menotexport   Author: Xunius   File: menotexport-gui.py    (license) View Source Project 5 votes vote down vote up
def initUI(self):
        self.parent.title(self.title)
        self.style=Style()
        #Choose from default, clam, alt, classic
        self.style.theme_use('alt')
        self.pack(fill=tk.BOTH,expand=True)
        self.centerWindow() 
Example 15
Project: cablefish   Author: michgur   File: menubar.py    (license) View Source Project 5 votes vote down vote up
def __init__(self, master):
        tk.Frame.__init__(self, master, bg='#F2F2F2')

        ttk.Style().layout('TMenubutton',
                           [('Menubutton.button', {'children':[('Menubutton.padding', {'children': [('Menubutton.label', {'sticky': ''})], 'expand': '1', 'sticky': 'we'})], 'expand': '1', 'sticky': 'nswe'})])

        self.file = ttk.Menubutton(self, text='File')
        self.file.menu = tk.Menu(self.file, tearoff=False)
        self.file.menu.add_command(label='New Capture', command=master.quit, accelerator='Ctrl+Enter')
        self.file.menu.add_command(label='Open', command=master.quit, accelerator='Ctrl+O')
        self.file.menu.add_command(label='Save', command=lambda: None)
        self.file.menu.add_command(label='Import', command=master.quit)
        self.file.menu.add_command(label='Export', command=master.quit)
        self.file.menu.add_separator()
        self.file.menu.add_command(label='Exit', command=master.app.quit, accelerator='Alt+F4')
        self.file['menu'] = self.file.menu

        self.edit = ttk.Menubutton(self, text='Edit')

        self.view = ttk.Menubutton(self, text='View')
        self.view.menu = tk.Menu(self.view, tearoff=False)
        self.view.menu.add_checkbutton(label='Rainbow', command=master.packets_panel.packets.toggle_rb)
        self.view.menu.add_checkbutton(label='Filter Hints', command=master.toggle_hints)
        self.view['menu'] = self.view.menu

        # self.poop = ttk.Menubutton(self, text='Poop') 
Example 16
Project: cablefish   Author: michgur   File: packet_info.py    (license) View Source Project 5 votes vote down vote up
def __init__(self, root):
        tk.Frame.__init__(self, root, bg='#10253F')

        self.packet = None

        self.label_border = tk.Frame(self, bg='#7F7F7F', height=35)
        self.label_border.pack_propagate(False)
        self.label = tk.Label(self.label_border, bg='#a68c7a', fg='#10253F', anchor=tk.W, padx=10, font='TkDefaultFont 12 bold')

        self.scroll = ttk.Scrollbar(self, style='Vertical.TScrollbar', orient=tk.VERTICAL)

        ttk.Style().layout('Fields.Treeview', [('Treeview.treearea', {'sticky': 'nswe'})])
        ttk.Style().configure('Fields.Treeview', background='#10253F', foreground='#FFFFFF')

        self.frame = tk.Frame(self, bg='#10253F')
        self.tree = ttk.Treeview(self.frame, show='tree', yscroll=self.scroll.set, style='Fields.Treeview')
        self.tree.tag_configure('layer', background='#20354F')
        self.scroll.config(command=self.tree.yview)

        self.opened_layers = set()

        self.tree.bind('<Control-c>', self.copy)

        # TODO
        # self.menu = tk.Menu(self)
        # self.menu.add_command(label='Insert As Filter', command=lambda: root.searchbar.insert(self.packet.getattr())) 
Example 17
Project: scl_jamf_tools   Author: univ-of-utah-marriott-library-apple   File: tugboat.py    (license) View Source Project 5 votes vote down vote up
def button_state(self):
        """
        sets buttons to the correct state
        """

        #
        # This method is used to enable/disable specific buttons, based on OS, etc.
        #
        # You want to use the Combobox option of state='disabled'.
        #
        # There are three options for state as follows:
        #
        #     state='normal' which is the fully functional Combobox.
        #     state='readonly' which is the Combobox with a value, but can't be changed (directly).
        #     state='disabled' which is where the Combobox cannot be interacted with.
        #
        # self.highlight_button = ttk.Style()
        # self.highlight_button.configure('Highlight.TButton', foreground='red')
        # ttk.Button(self.mainframe, text="Query this system", style='Highlight.TButton', command= lambda: self.query_jamf_me()).grid(column=2, row=20, padx =3, sticky=W)

        self.logger.info("%s: activated" % inspect.stack()[0][3])

        if self.platform == "Mac":
            self.jamf_management_btn.configure(state="normal")

        else:
            self.jamf_management_btn.configure(state="disabled") 
Example 18
Project: scl_jamf_tools   Author: univ-of-utah-marriott-library-apple   File: cargo_ship.py    (license) View Source Project 5 votes vote down vote up
def __init__(self, root, logger, jamf_hostname, jamf_username, jamf_password):
        """
        Initialize object and variables
        """
        self.root = root
        self.logger = logger
        self.jamf_hostname = jamf_hostname
        self.jamf_username = jamf_username
        self.jamf_password = jamf_password
        self.local_jamf_id = None

        self.computer_name_string = StringVar()
        self.fullname_string = StringVar()
        self.search_string = StringVar()
        self.status_string = StringVar()
        self.checkin_string = StringVar()
        self.id_string = StringVar()

        self.status_string.set("Ready.")

        self.status_warning = ttk.Style()
        self.status_warning.configure('Warning.TLabel', foreground='red')

        self.status_normal = ttk.Style()
        self.status_normal.configure('Normal.TLabel', foreground='black')

        #
        # These methods are time intensive based on the number of each in your database
        self.jamf_policies = self.build_policies()
        self.jamf_profiles = self.build_profiles()

        self.build_ui() 
Example 19
Project: SoftwareProject   Author: a-a-hofmann   File: fbgui.py    (license) View Source Project 5 votes vote down vote up
def __init__(self, master=None):
		    # create main frame
		    master = Tk()
		    #master.attributes('-zoomed', True)
		    #master.overrideredirect(True)
		    Frame.__init__(self, master)
		    self.master.title("Topology")
		    self.master.style = Style()
		    self.master.resizable(width = True, height = True)
		    # configure the geometry
		    self.grid(padx = 10, pady = 10)
		    # call the funtions
		    self.createWidgets()
		    self.paint_active_links()
		    self.paint_idle_links() 
Example 20
Project: SoftwareProject   Author: a-a-hofmann   File: rnpgui.py    (license) View Source Project 5 votes vote down vote up
def __init__(self, master=None):

                # create main frame
                master = Tk()
                Frame.__init__(self, master)
                self.master.title("Topology")
                self.master.style = Style()

                # configure the geometry
                self.grid(padx = 10, pady = 10)
		
                # call the funtions
               	self.createWidgets()			
		self.paint_topo() 
Example 21
Project: python2-tracer   Author: extremecoders-re   File: theme_selector.py    (license) View Source Project 4 votes vote down vote up
def __init__(self):
        ttk.Frame.__init__(self, borderwidth=3)

        self.style = ttk.Style()

        # XXX Ideally I wouldn't want to create a Tkinter.IntVar to make
        #     it works with Checkbutton variable option.
        self.theme_autochange = Tkinter.IntVar(self, 0)
        self._setup_widgets() 
Example 22
Project: qcri   Author: douville   File: gui.py    (license) View Source Project 4 votes vote down vote up
def __init__(self, cfg):
        tk.Tk.__init__(self)
        self.cfg = cfg  # ConfigParser

        self.qcc = None  # the Quality Center connection
        self.valid_parsers = {}
        self._cached_tests = {}  # for the treeview
        self._results = {}  # test results
        self.dir_dict = {}
        self.bug_dict = {}

        self.protocol("WM_DELETE_WINDOW", self.on_closing)
        self.title('QC Results Importer')
        center(self, 1200, 700)

        # tkinter widgets
        self.menubar = None
        self.remote_path = None
        self.choose_parser = None
        self.choose_results_button = None
        self.qcdir_tree = None
        self.upload_button = None
        self.choose_results_entry = None
        self.runresults_tree = None
        self.runresultsview = None
        self.header_frame = None
        self.qc_connected_frm = None
        self.qc_disconnected_frm = None
        self.link_bug = None

        self.qc_domain = tk.StringVar()
        self.attach_report = tk.IntVar()
        self.qc_project = tk.StringVar()
        self.runresultsvar = tk.StringVar()
        self.qc_conn_status = tk.BooleanVar()

        # build the gui        
        self._make()

        # style = ttk.Style()
        # style.theme_settings("default", {
        #     "TCombobox": {
        #         "configure": {"padding": 25}
        #     }
        # })