Python ttk 模块,Style() 实例源码

我们从Python开源项目中,提取了以下22个代码示例,用于说明如何使用ttk.Style()

项目:Smart-Trader    作者:i-sultan    | 项目源码 | 文件源码
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     |
#'----------------'
项目:StochOPy    作者:keurfonluu    | 项目源码 | 文件源码
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()
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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()
项目:cablefish    作者:michgur    | 项目源码 | 文件源码
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
项目:code    作者:ActiveState    | 项目源码 | 文件源码
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
项目:XimaExport    作者:ryankomodo    | 项目源码 | 文件源码
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()
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def setUp(self):
        super(StyleTest, self).setUp()
        self.style = ttk.Style(self.root)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def __init__(self):
        ttk.Frame.__init__(self)

        self.style = ttk.Style()
        self._setup_widgets()
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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'))
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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()
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def setUp(self):
        self.style = ttk.Style()
项目:Menotexport    作者:Xunius    | 项目源码 | 文件源码
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()
项目:image-copy-move-detection    作者:rahmatnazali    | 项目源码 | 文件源码
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()
项目:cablefish    作者:michgur    | 项目源码 | 文件源码
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')
项目:cablefish    作者:michgur    | 项目源码 | 文件源码
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()))
项目:cablefish    作者:michgur    | 项目源码 | 文件源码
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
项目:scl_jamf_tools    作者:univ-of-utah-marriott-library-apple    | 项目源码 | 文件源码
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")
项目:scl_jamf_tools    作者:univ-of-utah-marriott-library-apple    | 项目源码 | 文件源码
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()
项目:SoftwareProject    作者:a-a-hofmann    | 项目源码 | 文件源码
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()
项目:SoftwareProject    作者:a-a-hofmann    | 项目源码 | 文件源码
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()
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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()
项目:qcri    作者:douville    | 项目源码 | 文件源码
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}
        #     }
        # })