Python tkinter.ttk.Style() Examples

The following are 30 code examples for showing how to use tkinter.ttk.Style(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module tkinter.ttk , or try the search function .

Example 1
Project: synthesizer   Author: irmen   File: box.py    License: GNU Lesser General Public License v3.0 8 votes vote down vote up
def __init__(self, master):
        super().__init__(master, text="Levels", padding=4)
        self.lowest_level = Player.levelmeter_lowest
        self.pbvar_left = tk.IntVar()
        self.pbvar_right = tk.IntVar()
        pbstyle = ttk.Style()
        # pbstyle.theme_use("classic")  # clam, alt, default, classic
        pbstyle.configure("green.Vertical.TProgressbar", troughcolor="gray", background="light green")
        pbstyle.configure("yellow.Vertical.TProgressbar", troughcolor="gray", background="yellow")
        pbstyle.configure("red.Vertical.TProgressbar", troughcolor="gray", background="orange")

        ttk.Label(self, text="dB").pack(side=tkinter.TOP)
        frame = ttk.LabelFrame(self, text="L.")
        frame.pack(side=tk.LEFT)
        self.pb_left = ttk.Progressbar(frame, orient=tk.VERTICAL, length=200, maximum=-self.lowest_level,
                                       variable=self.pbvar_left, mode='determinate',
                                       style='yellow.Vertical.TProgressbar')
        self.pb_left.pack()

        frame = ttk.LabelFrame(self, text="R.")
        frame.pack(side=tk.LEFT)
        self.pb_right = ttk.Progressbar(frame, orient=tk.VERTICAL, length=200, maximum=-self.lowest_level,
                                        variable=self.pbvar_right, mode='determinate',
                                        style='yellow.Vertical.TProgressbar')
        self.pb_right.pack() 
Example 2
Project: fusee-interfacee-tk   Author: nh-server   File: app.py    License: GNU General Public License v2.0 7 votes vote down vote up
def build_widgets(self):
        style = ttk.Style()
        style.configure('Horizontal.TProgressbar', background='#5eba21')
        self.progress = ttk.Progressbar(self, mode='indeterminate', maximum=50)
        self.progress.grid(row=0, columnspan=2, sticky=tk.W+tk.E)
        self.progress.start(30)

        self.lbl_look = ttk.Label(self, text="Looking for Device...")
        self.lbl_look.grid(row=1, column=0, columnspan=2, pady=8)

        self.btn_open = ttk.Button(self, text="Select Payload", command=self.btn_open_pressed)
        self.btn_open.grid(row=2, column=0, padx=8)

        self.lbl_file = ttk.Label(self, text="No Payload Selected.    ", justify=tk.LEFT)
        self.lbl_file.grid(row=2, column=1, padx=8)

        self.btn_send = ttk.Button(self, text="Send Payload!", command=self.btn_send_pressed)
        self.btn_send.grid(row=3, column=0, columnspan=2, sticky=tk.W+tk.E, pady=8, padx=8)
        self.btn_send.state(('disabled',)) # trailing comma to define single element tuple

        self.btn_mountusb = ttk.Button(self, text="Mount SD on PC", command=self.btn_mountusb_pressed)
        self.btn_mountusb.grid(row=4, column=0, columnspan=2, sticky=tk.W+tk.E, pady=8, padx=8)
        self.btn_mountusb.state(('disabled',)) # trailing comma to define single element tuple 
Example 3
Project: Python-GUI-Programming-with-Tkinter   Author: PacktPublishing   File: widgets.py    License: MIT License 6 votes vote down vote up
def __init__(self, *args, error_var=None, **kwargs):
        self.error = error_var or tk.StringVar()
        super().__init__(*args, **kwargs)

        vcmd = self.register(self._validate)
        invcmd = self.register(self._invalid)

        style = ttk.Style()
        widget_class = self.winfo_class()
        validated_style = 'ValidatedInput.' + widget_class
        style.map(
            validated_style,
            foreground=[('invalid', 'white'), ('!invalid', 'black')],
            fieldbackground=[('invalid', 'darkred'), ('!invalid', 'white')]
        )

        self.config(
            style=validated_style,
            validate='all',
            validatecommand=(vcmd, '%P', '%s', '%S', '%V', '%i', '%d'),
            invalidcommand=(invcmd, '%P', '%s', '%S', '%V', '%i', '%d')
        ) 
Example 4
Project: Python-GUI-Programming-with-Tkinter   Author: PacktPublishing   File: widgets.py    License: MIT License 6 votes vote down vote up
def __init__(self, *args, error_var=None, **kwargs):
        self.error = error_var or tk.StringVar()
        super().__init__(*args, **kwargs)

        vcmd = self.register(self._validate)
        invcmd = self.register(self._invalid)

        style = ttk.Style()
        widget_class = self.winfo_class()
        validated_style = 'ValidatedInput.' + widget_class
        style.map(
            validated_style,
            foreground=[('invalid', 'white'), ('!invalid', 'black')],
            fieldbackground=[('invalid', 'darkred'), ('!invalid', 'white')]
        )

        self.config(
            style=validated_style,
            validate='all',
            validatecommand=(vcmd, '%P', '%s', '%S', '%V', '%i', '%d'),
            invalidcommand=(invcmd, '%P', '%s', '%S', '%V', '%i', '%d')
        ) 
Example 5
Project: Python-GUI-Programming-with-Tkinter   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def body(self, parent):
        lf = tk.Frame(self)
        ttk.Label(lf, text='Login to ABQ',
                  font='TkHeadingFont').grid(row=0)

        ttk.Style().configure('err.TLabel',
                background='darkred', foreground='white')
        if self.error.get():
            ttk.Label(lf, textvariable=self.error,
                      style='err.TLabel').grid(row=1)
        ttk.Label(lf, text='User name:').grid(row=2)
        self.username_inp = ttk.Entry(lf, textvariable=self.user)
        self.username_inp.grid(row=3)
        ttk.Label(lf, text='Password:').grid(row=4)
        self.password_inp = ttk.Entry(lf, show='*', textvariable=self.pw)
        self.password_inp.grid(row=5)
        lf.pack()
        return self.username_inp 
Example 6
Project: Python-GUI-Programming-with-Tkinter   Author: PacktPublishing   File: widgets.py    License: MIT License 6 votes vote down vote up
def __init__(self, *args, error_var=None, **kwargs):
        self.error = error_var or tk.StringVar()
        super().__init__(*args, **kwargs)

        vcmd = self.register(self._validate)
        invcmd = self.register(self._invalid)

        style = ttk.Style()
        widget_class = self.winfo_class()
        validated_style = 'ValidatedInput.' + widget_class
        style.map(
            validated_style,
            foreground=[('invalid', 'white'), ('!invalid', 'black')],
            fieldbackground=[('invalid', 'darkred'), ('!invalid', 'white')]
        )

        self.config(
            style=validated_style,
            validate='all',
            validatecommand=(vcmd, '%P', '%s', '%S', '%V', '%i', '%d'),
            invalidcommand=(invcmd, '%P', '%s', '%S', '%V', '%i', '%d')
        ) 
Example 7
Project: Python-GUI-Programming-with-Tkinter   Author: PacktPublishing   File: widgets.py    License: MIT License 6 votes vote down vote up
def __init__(self, *args, error_var=None, **kwargs):
        self.error = error_var or tk.StringVar()
        super().__init__(*args, **kwargs)

        vcmd = self.register(self._validate)
        invcmd = self.register(self._invalid)

        style = ttk.Style()
        widget_class = self.winfo_class()
        validated_style = 'ValidatedInput.' + widget_class
        style.map(
            validated_style,
            foreground=[('invalid', 'white'), ('!invalid', 'black')],
            fieldbackground=[('invalid', 'darkred'), ('!invalid', 'white')]
        )

        self.config(
            style=validated_style,
            validate='all',
            validatecommand=(vcmd, '%P', '%s', '%S', '%V', '%i', '%d'),
            invalidcommand=(invcmd, '%P', '%s', '%S', '%V', '%i', '%d')
        ) 
Example 8
Project: Python-GUI-Programming-with-Tkinter   Author: PacktPublishing   File: widgets.py    License: MIT License 6 votes vote down vote up
def __init__(self, *args, error_var=None, **kwargs):
        self.error = error_var or tk.StringVar()
        super().__init__(*args, **kwargs)

        vcmd = self.register(self._validate)
        invcmd = self.register(self._invalid)

        style = ttk.Style()
        widget_class = self.winfo_class()
        validated_style = 'ValidatedInput.' + widget_class
        style.map(
            validated_style,
            foreground=[('invalid', 'white'), ('!invalid', 'black')],
            fieldbackground=[('invalid', 'darkred'), ('!invalid', 'white')]
        )

        self.config(
            style=validated_style,
            validate='all',
            validatecommand=(vcmd, '%P', '%s', '%S', '%V', '%i', '%d'),
            invalidcommand=(invcmd, '%P', '%s', '%S', '%V', '%i', '%d')
        ) 
Example 9
Project: Python-GUI-Programming-with-Tkinter   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def body(self, parent):
        lf = tk.Frame(self)
        ttk.Label(lf, text='Login to ABQ',
                  font='TkHeadingFont').grid(row=0)

        ttk.Style().configure('err.TLabel',
                background='darkred', foreground='white')
        if self.error.get():
            ttk.Label(lf, textvariable=self.error,
                      style='err.TLabel').grid(row=1)
        ttk.Label(lf, text='User name:').grid(row=2)
        self.username_inp = ttk.Entry(lf, textvariable=self.user)
        self.username_inp.grid(row=3)
        ttk.Label(lf, text='Password:').grid(row=4)
        self.password_inp = ttk.Entry(lf, show='*', textvariable=self.pw)
        self.password_inp.grid(row=5)
        lf.pack()
        return self.username_inp 
Example 10
Project: Python-GUI-Programming-with-Tkinter   Author: PacktPublishing   File: widgets.py    License: MIT License 6 votes vote down vote up
def __init__(self, *args, error_var=None, **kwargs):
        self.error = error_var or tk.StringVar()
        super().__init__(*args, **kwargs)

        vcmd = self.register(self._validate)
        invcmd = self.register(self._invalid)

        style = ttk.Style()
        widget_class = self.winfo_class()
        validated_style = 'ValidatedInput.' + widget_class
        style.map(
            validated_style,
            foreground=[('invalid', 'white'), ('!invalid', 'black')],
            fieldbackground=[('invalid', 'darkred'), ('!invalid', 'white')]
        )

        self.config(
            style=validated_style,
            validate='all',
            validatecommand=(vcmd, '%P', '%s', '%S', '%V', '%i', '%d'),
            invalidcommand=(invcmd, '%P', '%s', '%S', '%V', '%i', '%d')
        ) 
Example 11
Project: Python-GUI-Programming-with-Tkinter   Author: PacktPublishing   File: widgets.py    License: MIT License 6 votes vote down vote up
def __init__(self, *args, error_var=None, **kwargs):
        self.error = error_var or tk.StringVar()
        super().__init__(*args, **kwargs)

        vcmd = self.register(self._validate)
        invcmd = self.register(self._invalid)

        style = ttk.Style()
        widget_class = self.winfo_class()
        validated_style = 'ValidatedInput.' + widget_class
        style.map(
            validated_style,
            foreground=[('invalid', 'white'), ('!invalid', 'black')],
            fieldbackground=[('invalid', 'darkred'), ('!invalid', 'white')]
        )

        self.config(
            style=validated_style,
            validate='all',
            validatecommand=(vcmd, '%P', '%s', '%S', '%V', '%i', '%d'),
            invalidcommand=(invcmd, '%P', '%s', '%S', '%V', '%i', '%d')
        ) 
Example 12
Project: Python-GUI-Programming-with-Tkinter   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def body(self, parent):
        lf = tk.Frame(self)
        ttk.Label(lf, text='Login to ABQ',
                  font='TkHeadingFont').grid(row=0)

        ttk.Style().configure('err.TLabel',
                background='darkred', foreground='white')
        if self.error.get():
            ttk.Label(lf, textvariable=self.error,
                      style='err.TLabel').grid(row=1)
        ttk.Label(lf, text='User name:').grid(row=2)
        self.username_inp = ttk.Entry(lf, textvariable=self.user)
        self.username_inp.grid(row=3)
        ttk.Label(lf, text='Password:').grid(row=4)
        self.password_inp = ttk.Entry(lf, show='*', textvariable=self.pw)
        self.password_inp.grid(row=5)
        lf.pack()
        return self.username_inp 
Example 13
Project: Python-GUI-Programming-with-Tkinter   Author: PacktPublishing   File: widgets.py    License: MIT License 6 votes vote down vote up
def __init__(self, *args, error_var=None, **kwargs):
        self.error = error_var or tk.StringVar()
        super().__init__(*args, **kwargs)

        vcmd = self.register(self._validate)
        invcmd = self.register(self._invalid)

        style = ttk.Style()
        widget_class = self.winfo_class()
        validated_style = 'ValidatedInput.' + widget_class
        style.map(
            validated_style,
            foreground=[('invalid', 'white'), ('!invalid', 'black')],
            fieldbackground=[('invalid', 'darkred'), ('!invalid', 'white')]
        )

        self.config(
            style=validated_style,
            validate='all',
            validatecommand=(vcmd, '%P', '%s', '%S', '%V', '%i', '%d'),
            invalidcommand=(invcmd, '%P', '%s', '%S', '%V', '%i', '%d')
        ) 
Example 14
Project: ttkwidgets   Author: TkinterEP   File: table.py    License: GNU General Public License v3.0 6 votes vote down vote up
def _initialize_style(self):
        style = ttk.Style(self)
        style.layout('Table', style.layout('Treeview'))
        style.layout('Table.Heading',
                     [('Treeheading.cell', {'sticky': 'nswe'}),
                      ('Treeheading.border',
                       {'sticky': 'nswe',
                        'children': [('Treeheading.padding',
                                      {'sticky': 'nswe',
                                       'children': [('Treeheading.image', {'side': 'left', 'sticky': ''}),
                                                    ('Treeheading.text', {'sticky': 'we'})]})]})])
        config = style.configure('Treeview')
        if config:
            style.configure('Table', **config)
        config_heading = style.configure('Treeview.Heading')
        if config_heading:
            style.configure('Table.Heading', **config_heading)
        style_map = style.map('Treeview')
        # add noticeable disabled style
        fieldbackground = style_map.get('fieldbackground', [])
        fieldbackground.append(("disabled", '#E6E6E6'))
        style_map['fieldbackground'] = fieldbackground
        foreground = style_map.get('foreground', [])
        foreground.append(("disabled", 'gray40'))
        style_map['foreground'] = foreground
        background = style_map.get('background', [])
        background.append(("disabled", '#E6E6E6'))
        style_map['background'] = background
        style.map('Table', **style_map)

        style_map_heading = style.map('Treeview.Heading')
        style.map('Table.Heading', **style_map_heading) 
Example 15
Project: ttkwidgets   Author: TkinterEP   File: checkboxtreeview.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, master=None, **kw):
        """
        Create a CheckboxTreeview.

        :param master: master widget
        :type master: widget
        :param kw: options to be passed on to the :class:`ttk.Treeview` initializer
        """
        ttk.Treeview.__init__(self, master, style='Checkbox.Treeview', **kw)
        # style (make a noticeable disabled style)
        style = ttk.Style(self)
        style.map("Checkbox.Treeview",
                  fieldbackground=[("disabled", '#E6E6E6')],
                  foreground=[("disabled", 'gray40')],
                  background=[("disabled", '#E6E6E6')])
        # checkboxes are implemented with pictures
        self.im_checked = ImageTk.PhotoImage(Image.open(IM_CHECKED), master=self)
        self.im_unchecked = ImageTk.PhotoImage(Image.open(IM_UNCHECKED), master=self)
        self.im_tristate = ImageTk.PhotoImage(Image.open(IM_TRISTATE), master=self)
        self.tag_configure("unchecked", image=self.im_unchecked)
        self.tag_configure("tristate", image=self.im_tristate)
        self.tag_configure("checked", image=self.im_checked)
        # check / uncheck boxes on click
        self.bind("<Button-1>", self._box_click, True) 
Example 16
def trans(self):
        gui_style = ttk.Style()
        gui_style.configure('Ui.TButton', foreground='#FF0000')
        self.trans_button.config(style='Ui.TButton')
        self.run_queue.put(1)
        if self.input_text.get():
            query_string = self.input_text.get()
        else:
            try:
                query_string = self.window.clipboard_get()
                self.window.clipboard_clear()
            except Exception as e:
                query_string = str(e)
        Args.query = query_string
        trans_result = trans(Args)
        self.st.delete('1.0', tk.END)
        self.st.insert(tk.END, trans_result)
        self.run_queue.get()
        gui_style.configure('Ui.TButton', foreground='#000000') 
Example 17
Project: hwk-mirror   Author: BnetButter   File: tkwidgets.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, parent, *tabs, **kwargs):
        super().__init__(parent, **kwargs)
        
        assert all(isinstance(t, str) for t in tabs)

        self.style = ttk.Style(self)
        self.style.configure("TNotebook.Tab")
        self._notebook = ttk.Notebook(self, style="TNotebook")
        self.data = {
            name: tk.Frame(self._notebook)
            for name in tabs}
        self._tab_ids = {}
        for name in self.data:
            self._notebook.add(self.data[name], text=name)
            self._tab_ids[name] = self._notebook.tabs()[-1]
        
        self.grid_columnconfigure(0, weight=1)
        self.grid_rowconfigure(0, weight=1)

        self._notebook.grid(row=0, column=0, sticky="nswe") 
Example 18
Project: cheetah-gui   Author: shmilylty   File: cheetah_update.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, top=None):
        """This class configures and populates the toplevel window.
           top is the toplevel containing window."""
        _bgcolor = '#d9d9d9'  # X11 color: 'gray85'
        _fgcolor = '#000000'  # X11 color: 'black'
        _compcolor = '#d9d9d9'  # X11 color: 'gray85'
        _ana1color = '#d9d9d9'  # X11 color: 'gray85'
        self.style = ttk.Style()
        if sys.platform == "win32":
            self.style.theme_use('winnative')
        self.style.configure('.', background=_bgcolor)
        self.style.configure('.', foreground=_fgcolor)
        self.style.configure('.', font="TkDefaultFont")
        self.style.map('.', background=[('selected', _compcolor), ('active', _ana1color)])

        top.geometry("388x169+474+249")
        top.title("Cheetah Update")
        top.configure(background="#d9d9d9")
        top.configure(highlightbackground="#d9d9d9")
        top.configure(highlightcolor="black")

        self.TButton1 = ttk.Button(top)
        self.TButton1.place(relx=0.23, rely=0.71, height=27, width=87)
        self.TButton1.configure(command=cheetah_update_support.check_updates)
        self.TButton1.configure(takefocus="")
        self.TButton1.configure(textvariable=cheetah_update_support.check_update)

        self.Message1 = Message(top)
        self.Message1.place(relx=0.05, rely=0.12, relheight=0.44, relwidth=0.87)
        self.Message1.configure(background="#d9d9d9")
        self.Message1.configure(foreground="#000000")
        self.Message1.configure(highlightbackground="#d9d9d9")
        self.Message1.configure(highlightcolor="black")
        self.Message1.configure(textvariable=cheetah_update_support.update_msg)
        self.Message1.configure(width=337)

        self.TButton2 = ttk.Button(top)
        self.TButton2.place(relx=0.57, rely=0.71, height=27, width=87)
        self.TButton2.configure(command=cheetah_update_support.exit_update)
        self.TButton2.configure(takefocus="")
        self.TButton2.configure(text='''Cancel''') 
Example 19
Project: stochopy   Author: keurfonluu   File: gui.py    License: MIT License 6 votes vote down vote up
def main():
    """
    Start StochOPy Viewer window.
    """
    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 20
Project: JAVER_Assist   Author: tywings   File: main_gui.py    License: MIT License 6 votes vote down vote up
def __tabs_creator(self):
        style = ttk.Style()
        style.theme_create('st', settings={
            ".": {
                "configure": {
                    "background": self.__BG_GREY,
                    "font": self.__FONT
                }
            },
            "TNotebook": {
                "configure": {
                    "tabmargins": [2, 5, 0, 0],
                }
            },
            "TNotebook.Tab": {
                "configure": {
                    "padding": [10, 2]
                },
                "map": {
                    "background": [("selected", self.__FG_GREY)],
                    "expand": [("selected", [1, 1, 1, 0])]
                }
            }
        })
        style.theme_use('st')

        tab_control = ttk.Notebook(self.root)

        tab1 = ttk.Frame(tab_control)
        tab_control.add(tab1, text='主页')
        self.__tab1_content(tab1)

        tab2 = ttk.Frame(tab_control)
        tab_control.add(tab2, text='设置')
        self.__tab2_content(tab2)

        tab3 = ttk.Frame(tab_control)
        tab_control.add(tab3, text='关于')

        tab_control.place(x=0, y=0, width=900, height=550) 
Example 21
Project: clai   Author: IBM   File: clai_emulator.py    License: MIT License 6 votes vote down vote up
def launch(self):
        self.root = tk.Tk()
        self.root.wait_visibility(self.root)
        self.title_font = Font(size=16, weight='bold')
        self.bold_font = Font(weight='bold')

        self.root.geometry("900x600")

        style = ttk.Style(self.root)
        style.configure("TLable", bg="black")

        self.add_toolbar(self.root)
        self.add_send_command_box(self.root)
        self.add_list_commands(self.root)

        self.root.protocol("WM_DELETE_WINDOW", lambda root=self.root: self.on_closing(root))
        self.root.createcommand('exit', lambda root=self.root: self.on_closing(root))

        self.root.mainloop() 
Example 22
Project: tkcalendar   Author: j4321   File: dateentry.py    License: GNU General Public License v3.0 6 votes vote down vote up
def _setup_style(self, event=None):
        """Style configuration to make the DateEntry look like a Combobbox."""
        self.style.layout('DateEntry', self.style.layout('TCombobox'))
        self.update_idletasks()
        conf = self.style.configure('TCombobox')
        if conf:
            self.style.configure('DateEntry', **conf)
        maps = self.style.map('TCombobox')
        if maps:
            try:
                self.style.map('DateEntry', **maps)
            except tk.TclError:
                # temporary fix for issue #61 and https://bugs.python.org/issue38661
                maps = MAPS.get(self.style.theme_use(), MAPS['default'])
                self.style.map('DateEntry', **maps)
        try:
            self.after_cancel(self._determine_downarrow_name_after_id)
        except ValueError:
            # nothing to cancel
            pass
        self._determine_downarrow_name_after_id = self.after(10, self._determine_downarrow_name) 
Example 23
Project: faceswap   Author: deepfakes   File: control_helper.py    License: GNU General Public License v3.0 6 votes vote down vote up
def add_info(self, frame):
        """ Plugin information """
        gui_style = ttk.Style()
        gui_style.configure('White.TFrame', background='#FFFFFF')
        gui_style.configure('Header.TLabel',
                            background='#FFFFFF',
                            font=get_config().default_font + ("bold", ))
        gui_style.configure('Body.TLabel',
                            background='#FFFFFF')

        info_frame = ttk.Frame(frame, style='White.TFrame', relief=tk.SOLID)
        info_frame.pack(fill=tk.X, side=tk.TOP, expand=True, padx=10, pady=10)
        label_frame = ttk.Frame(info_frame, style='White.TFrame')
        label_frame.pack(padx=5, pady=5, fill=tk.X, expand=True)
        for idx, line in enumerate(self.header_text.splitlines()):
            if not line:
                continue
            style = "Header.TLabel" if idx == 0 else "Body.TLabel"
            info = ttk.Label(label_frame, text=line, style=style, anchor=tk.W)
            info.bind("<Configure>", self._adjust_wraplength)
            info.pack(fill=tk.X, padx=0, pady=0, expand=True, side=tk.TOP) 
Example 24
Project: thonny   Author: thonny   File: ui_utils.py    License: MIT License 6 votes vote down vote up
def __init__(self, master):
        ttk.Frame.__init__(self, master, style="CustomMenubar.TFrame")
        self._menus = []
        self._opened_menu = None

        ttk.Style().map(
            "CustomMenubarLabel.TLabel",
            background=[
                ("!active", lookup_style_option("Menubar", "background", "gray")),
                ("active", lookup_style_option("Menubar", "activebackground", "LightYellow")),
            ],
            foreground=[
                ("!active", lookup_style_option("Menubar", "foreground", "black")),
                ("active", lookup_style_option("Menubar", "activeforeground", "black")),
            ],
        ) 
Example 25
Project: thonny   Author: thonny   File: ui_utils.py    License: MIT License 6 votes vote down vote up
def _reload_theme_options(self, event=None):
        style = ttk.Style()

        states = []
        if self["state"] == "disabled":
            states.append("disabled")

        # Following crashes when a combobox is focused
        # if self.focus_get() == self:
        #    states.append("focus")
        opts = {}
        for key in [
            "background",
            "foreground",
            "highlightthickness",
            "highlightcolor",
            "highlightbackground",
        ]:
            value = style.lookup(self.get_style_name(), key, states)
            if value:
                opts[key] = value

        self.configure(opts) 
Example 26
Project: thonny   Author: thonny   File: tktextext.py    License: MIT License 6 votes vote down vote up
def _reload_theme_options(self, event=None):

        style = ttk.Style()

        states = []
        if self.is_read_only():
            states.append("readonly")

        # Following crashes when a combobox is focused
        # if self.focus_get() == self:
        #    states.append("focus")

        if "background" not in self._initial_configuration:
            background = style.lookup(self._style, "background", states)
            if background:
                self.configure(background=background)

        if "foreground" not in self._initial_configuration:
            foreground = style.lookup(self._style, "foreground", states)
            if foreground:
                self.configure(foreground=foreground)
                self.configure(insertbackground=foreground) 
Example 27
Project: thonny   Author: thonny   File: variables.py    License: MIT License 6 votes vote down vote up
def __init__(self, master):
        super().__init__(master)

        ttk.Style().configure("Centered.TButton", justify="center")
        self.back_button = ttk.Button(
            self.tree,
            style="Centered.TButton",
            text=_("Back to\ncurrent frame"),
            command=self._handle_back_button,
            width=15,
        )

        get_workbench().bind("BackendRestart", self._handle_backend_restart, True)
        get_workbench().bind("ToplevelResponse", self._handle_toplevel_response, True)
        # get_workbench().bind("DebuggerResponse", self._debugger_response, True)
        get_workbench().bind("get_frame_info_response", self._handle_frame_info_event, True)
        get_workbench().bind("get_globals_response", self._handle_get_globals_response, True)

        # records last info from progress messages
        self._last_active_info = None 
Example 28
Project: Tkinter-GUI-Application-Development-Cookbook   Author: PacktPublishing   File: chapter8_07.py    License: MIT License 6 votes vote down vote up
def create_header(self):
        left_arrow = {'children': [('Button.leftarrow', None)]}
        right_arrow = {'children': [('Button.rightarrow', None)]}
        style = ttk.Style(self)
        style.layout('L.TButton', [('Button.focus', left_arrow)])
        style.layout('R.TButton', [('Button.focus', right_arrow)])

        hframe = ttk.Frame(self)
        btn_left = ttk.Button(hframe, style='L.TButton',
                              command=lambda: self.move_month(-1))
        btn_right = ttk.Button(hframe, style='R.TButton',
                               command=lambda: self.move_month(1))
        label = ttk.Label(hframe, width=15, anchor='center')

        hframe.pack(pady=5, anchor=tk.CENTER)
        btn_left.grid(row=0, column=0)
        label.grid(row=0, column=1, padx=12)
        btn_right.grid(row=0, column=2)
        return label 
Example 29
Project: halucinator   Author: embedded-sec   File: SymbolBrowser.py    License: GNU General Public License v3.0 6 votes vote down vote up
def set_layout(self):
        '''
            Sets the layout for the gui
        '''
        s = ttk.Style()
        s.theme_use('clam')

        # Layout column 0
        self.table_funcs.grid(column=0, row=0, sticky=tk.W+tk.E)
        self.tree.grid(column=0, row=1, sticky=tk.W+tk.E+tk.N+tk.S)

        # Layout column 1
        self.record_label.grid(column=1, row=0, sticky=tk.W+tk.E)
        self.record_tree.grid(column=1, row=1, sticky=tk.W+tk.E+tk.N+tk.S)

        self.root.grid_columnconfigure(0, minsize=300)
        self.root.grid_columnconfigure(1, weight=1, minsize=500)
        self.root.grid_rowconfigure(1, weight=1) 
Example 30
Project: halucinator   Author: embedded-sec   File: symbol_browser.py    License: GNU General Public License v3.0 6 votes vote down vote up
def set_layout(self):
        '''
            Sets the layout for the gui
        '''
        s = ttk.Style()
        s.theme_use('clam')

        # Layout column 0
        self.table_funcs.grid(column=0, row=0, sticky=tk.W+tk.E)
        self.tree.grid(column=0, row=1, sticky=tk.W+tk.E+tk.N+tk.S)

        # Layout column 1
        self.record_label.grid(column=1, row=0, sticky=tk.W+tk.E)
        self.record_tree.grid(column=1, row=1, sticky=tk.W+tk.E+tk.N+tk.S)

        self.root.grid_columnconfigure(0, minsize=300)
        self.root.grid_columnconfigure(1, weight=1, minsize=500)
        self.root.grid_rowconfigure(1, weight=1)