【问题标题】:Is it possible to get Windows 10 style buttons in Tkinter? (Python 3.5.2)是否可以在 Tkinter 中获得 Windows 10 样式的按钮? (Python 3.5.2)
【发布时间】:2017-08-23 13:51:01
【问题描述】:

我有一个小的 Python GUI,它只是微软记事本的一个更小、更不高级的版本。它允许加载和保存文件等,以及一些其他基本菜单选项,例如退出。

Tkinter 通常可以很好地创建此类程序,但我想知道是否可以使用外观漂亮得多的 Windows 10 按钮,而不是使用外观丑陋的 Tkinter 按钮。 (见下图不同,Tkinter 是上图,Windows 是下图)。

我知道这是一个晦涩难懂的问题,但如果有人知道这是否可能,我会非常高兴。没有什么比一个看起来很干净的程序更让我开心的了 :) 不过我有疑问...

下面是用于我当前按钮的代码(我知道 .place 有多么尴尬,但它现在对我有用):)

yes = Button(confirmation, text = "Yes", command = ProgramTerminate, width = 5, height = 1)
yes.place(x = 100, y = 25)

no = Button(confirmation, text = "No", command = confirmation.destroy, width = 5, height = 1)
no.place(x = 150, y = 25)

【问题讨论】:

    标签: python-3.x user-interface button tkinter


    【解决方案1】:

    没有。您可以使用 ttk 获得 Windows 7ish 外观:

    from tkinter import ttk
    yes = ttk.Button(confirmation, text = "Yes", command = ProgramTerminate, width = 5, height = 1)
    

    但是,我看到您正在制作一个是/否消息框。您可以使用messagebox.askyesno 调用系统的版本:

    from tkinter import messagebox
    
    response = messagebox.askyesno("Really Quit?", "Are you sure you want to quit?")
    if response:
       ProgramTerminate()
    

    【讨论】:

    • 谢谢!比我做的更接近,现在看起来更专业了:)
    • "height" 选项尚未在 tkk.button 中实现
    猜你喜欢
    • 2019-02-06
    • 1970-01-01
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    • 2021-02-24
    • 2017-05-28
    • 1970-01-01
    • 2018-04-06
    相关资源
    最近更新 更多