Tkinter look (theme) in Linux

后端 未结 3 768
自闭症患者
自闭症患者 2021-02-02 01:04

I know that Tkinter is not so modern, not so cool and maybe better to use PyQt or etc.

But it is interesting for me can Tkinter look not so ugly in Ubuntu (Linux). Looks

3条回答
  •  一个人的身影
    2021-02-02 01:29

    All available themes of ttk can be seen with such commands:

    $ python
    >>> import ttk
    >>> s=ttk.Style()
    >>> s.theme_names()
    ('clam', 'alt', 'default', 'classic')
    

    So you can use 'clam', 'alt', 'default', 'classic' themes with your version of Tkinter.

    After trying all of them I think the best one is 'clam'. You can use this one or any other in following way:

    from Tkinter import *
    from ttk import *
    
    class App():
      def __init__(self, master):
        frame = Frame(master)
        frame.pack()
    
        master.title("Just my example")
        self.label = Label(frame, text="Type very long text:")
    
        self.entry = Entry(frame)
    
        self.button = Button(frame,
                             text="Quit", width=15,
                             command=frame.quit)
    
    
        self.slogan = Button(frame,
                             text="Hello", width=15,
                             command=self.write_slogan)
    
        self.label.grid(row=0, column=0)
        self.entry.grid(row=0, column=1)
        self.slogan.grid(row=1, column=0, sticky='e')
        self.button.grid(row=1, column=1, sticky='e')
    
      def write_slogan(self):
        print "Tkinter is easy to use!"
    
    root = Tk()
    root.style = Style()
    #('clam', 'alt', 'default', 'classic')
    root.style.theme_use("clam")
    
    app = App(root)
    root.mainloop()
    

    Result:

    enter image description here

    OS X uses precompiled theme "aqua" so widgets are looking better.

    Also Ttk widgets do not support all option which pure Tkinter does.

提交回复
热议问题