设置菜单栏

效果如下:

 

代码:

 1 """
 2 This program creates a menubar.
 3 The menubar has one menu with an exit action.
 4 """
 5 
 6 import sys
 7 from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication
 8 from PyQt5.QtGui import QIcon
 9 
10 
11 class Example(QMainWindow):
12 
13     def __init__(self):
14         super().__init__()
15 
16         self.initUI()
17 
18     def initUI(self):
19 
20         # create an action with a specific icon and an 'Exit' label.
21         exitAct = QAction(QIcon('pictures\exit.png'), '&Exit', self)
22 
23         # a shortcut is defined for this action
24         exitAct.setShortcut('Ctrl+Q')
25         # creates a status tip which is shown in the statusbar
26         # when we hover a mouse pointer over the menu item
27         exitAct.setStatusTip('Exit application')
28         # The signal is connected to the quit() method of the QApplication widget
29         exitAct.triggered.connect(qApp.quit)
30 
31         self.statusBar()
32 
33         # The menuBar() method creates a menubar
34         menubar = self.menuBar()
35         # create a file menu with addMenu()
36         fileMenu = menubar.addMenu('&File')
37         # add the action with addAction()
38         fileMenu.addAction(exitAct)
39 
40         self.setGeometry(300, 300, 300, 200)
41         self.setWindowTitle('Simple menu')
42         self.show()
43 
44 
45 if __name__ == '__main__':
46 
47     app = QApplication(sys.argv)
48     ex = Example()
49     sys.exit(app.exec_())

 

转载于:https://www.cnblogs.com/fuqia/p/8708650.html

在 PyCharm 中,调整菜单栏字体大小通常不是直接通过编辑器的字体设置来完成的,因为菜单栏字体属于操作系统级别的 UI 字体。不过,可以通过以下几种方式来间接调整菜单栏字体大小: ### 调整 PyCharm 菜单栏字体大小的方法 1. **更改操作系统 DPI 设置** 由于 PyCharm 的菜单栏字体依赖于操作系统的 UI 渲染,因此可以通过调整 Windows 的 DPI 缩放比例来放大菜单栏字体: - 打开“设置” > “系统” > “显示”。 - 找到“缩放与布局”部分,调整“更改文本、应用等项目的大小”选项,例如设置为 125% 或 150%。 - 应用更改后,PyCharm 的菜单栏字体也会随之变大[^2]。 2. **使用高 DPI 缩放行为设置** 对于某些高分辨率显示器,PyCharm 可能没有正确适配 DPI 缩放,可以手动修改 PyCharm 的 `.vmoptions` 文件以启用更精确的缩放: - 找到 PyCharm 的安装目录,进入 `bin` 文件夹。 - 编辑 `pycharm64.vmoptions`(或 `pycharm.vmoptions`)文件。 - 添加以下行以启用自定义 DPI 缩放: ``` -Dsun.java2d.uiScale=1.5 ``` 其中 `1.5` 表示 150% 的缩放比例,可以根据需要调整为 `1.25` 或 `2.0` 等值。 - 保存文件并重启 PyCharm。 3. **更改主题或使用自定义主题插件** 如果希望更精细地控制 UI 字体(包括菜单栏),可以尝试使用第三方插件如 *UI Options* 或 *Custom UI Font*: - 打开 PyCharm,进入 `Settings` > `Plugins`。 - 搜索 “Custom UI Font” 插件并安装。 - 启用插件后,在 `Settings` > `Custom UI Font` 中设置菜单栏、工具栏等 UI 元素的字体大小和样式。 4. **调整 PyCharm 的全局字体设置(影响编辑器界面)** 虽然这不会直接影响菜单栏字体,但可以提升整体界面可读性: - 打开 `Settings` > `Editor` > `Font`。 - 设置主字体和大小,例如将主字体大小从默认的 12pt 调整为 14pt[^1]。 ### 示例代码:使用 Tkinter 设置字体大小 以下是一个简单的 Python 示例,展示如何使用 `tkinter` 设置字体大小,虽然主要用于 GUI 应用程序,但可以帮助理解字体设置的一般方式: ```python import tkinter as tk root = tk.Tk() root.title("设置字体大小示例") # 创建一个标签并设置字体大小为14 label = tk.Label(root, text="Hello, World!", font=("Arial", 14)) label.pack() root.mainloop() ``` ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值