python – Linux中的Tkinter外观(主题)
发布时间:2021-01-12 00:16:33  所属栏目:Python  来源:互联网 
            导读:我知道Tkinter不是那么现代,不太酷,也许更好地使用PyQt等. 但有趣的是,Tkinter在Ubuntu(Linux)中看起来并不那么难看.看起来使用内置主题编译的python的Tkinter的brew版本(在OS X中)看起来很好: 但是Ubuntu的Tkinter让我哭了: 我已经读过,为了好主题,我需要
                
                
                
            | 
                         我知道Tkinter不是那么现代,不太酷,也许更好地使用PyQt等. 但有趣的是,Tkinter在Ubuntu(Linux)中看起来并不那么难看.看起来使用内置主题编译的python的Tkinter的brew版本(在OS X中)看起来很好: 但是Ubuntu的Tkinter让我哭了: 我已经读过,为了好主题,我需要使用ttk,但我不确切知道如何.我的代码如下: from Tkinter 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",fg="red",width=20,command=frame.quit)
    self.slogan = Button(frame,text="Hello",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)
    self.button.grid(row=1,column=1)
  def write_slogan(self):
    print "Tkinter is easy to use!"
root = Tk()
app = App(root)
root.mainloop() 
 如何应用标准的ubuntu主题或至少更好的主题? 谢谢. 解决方法可以使用以下命令查看ttk的所有可用主题:$python
>>> import ttk
>>> s=ttk.Style()
>>> s.theme_names()
('clam','alt','default','classic') 
 所以你可以在你的Tkinter版本中使用’clam’,’alt’,’default’,’classic’主题. 在尝试了所有这些之后,我认为最好的是’蛤蜊’.您可以通过以下方式使用此项或任何其他项: from Tkinter import *
from ttk import *
class App():
  def __init__(self,width=15,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','classic')
root.style.theme_use("clam")
app = App(root)
root.mainloop() 
 结果: OS X使用预编译的主题“aqua”,因此小部件看起来更好. 此外,Ttk小部件不支持纯Tkinter所做的所有选项. (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
相关内容
- python – 将MIMEText编码为引用的可打印文件
 - python 之路,Django rest framework 初探
 - Python:如何在字符串中剪切超过2个相等字符的序列
 - python-2.7 – 无法安装PythonMagick Windows 7
 - python代码是解释型语言,为什么还有编译过程?
 - Python 2和3之间的类型差异
 - python – Django模板将模板变量传递到剪切过滤器
 - python – django:django-tables2 DetailView CBV不会显示
 - python – matplotlib自定义图例中类别的子标题
 - 分析Django webserver以获得高启动时间
 
