Python Tkinter:如何修改菜单小部件的字体? [英] Python Tkinter: How to modify the font of the Menu widget?

查看:32
本文介绍了Python Tkinter:如何修改菜单小部件的字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Courier Newfont 制作一个 tkinter Menu 小部件.不幸的是 font 属性 似乎不起作用.我正在使用 Python 3.4.1.代码如下:

I am trying to make a tkinter Menu widget with the font of Courier New. Unfortunately the font attribute doesn't seem to be working. I am using Python 3.4.1. Below is the code:

from tkinter import *

class Arshi(Frame):

    def __init__(self, master):
        Frame.__init__(self, master)
        self.pack(fill=BOTH)
        self.topbar()

    def topbar(self):
        self.menufont = ("Courier New", 9)
        self.menu = Menu(self, font=self.menufont)
        self.master.config(menu=self.menu)

root = Tk()
root.title("Arshi")
window = Arshi(root)
window.mainloop()

推荐答案

Tkinter 是一个 Python 绑定到 Tk 小部件.Tk 的菜单小部件设计为具有不可编程的字体.这是其他流行的小部件工具包在 GUI 开发中采用的方法,即:

Tkinter is a Python binding to Tk widgets. Tk's menu widget is designed to have a non-programmable font. That is the approach other popular widget toolkits have taken under GUI development, namely:

-- 无论使用哪个工具包来创建系统的应用程序,它都应该具有标准化的菜单.
-- 所有应用程序菜单字体都可由单个用户在单个系统范围的配置选项下进行配置(查找您系统的用户设置以获取菜单的字体设置).
-- 无论您使用 Tk 还是竞争对手的小部件,所有菜单看起来都相同.
-- 如果另一个菜单确实看起来不同,那么它就不是真正的菜单小部件.

-- A system's applications should have standardized menus no matter which toolkit was used to create it.
-- All applications menu-fonts are configurable by the individual user under a single system-wide configuration option (look for your system's user setting for the font settings for menus).
-- All menus will look the same, regardless of whether you use Tk or a competitors widget.
-- If another menu does look different, then it's not really a menu widget.

例如,在 Ubuntu 中,应用程序菜单将被抛出到屏幕的左上角,与主应用程序窗口分开.OS-X 有类似的方法.Windows、Mac 和 Linux 桌面都允许他们的个人用户根据个人喜好调整菜单字体,但不能根据程序员的个人喜好调整菜单字体.

For example, within Ubuntu, an applications menu will be thrown to the top-left of the screen, separate from the main application window. OS-X has a similar approach. Windows, Mac and Linux Desktops all allow their individual users to adjust their menu fonts to their personal preference, but not to the programmer's personal preference.

可以使用另一个小部件类来模仿菜单的外观,程序员可以通过这种方式根据自己的个人喜好自定义字体.例如,您可以使用 menubutton 小部件并调整它的字体选项,并将它们放置在一个框架内.然后它将用于非标准菜单.

It is possible to use another widget class to mimic the appearance of a menu, and the programmer can customize the font to their own personal liking that way. For example, you can use the menubutton widget and adjust it's font option, and place those within a frame. It would then serve the purpose of a non-standard menu.

这篇关于Python Tkinter:如何修改菜单小部件的字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆