{"id":1183280,"date":"2025-01-15T19:12:45","date_gmt":"2025-01-15T11:12:45","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1183280.html"},"modified":"2025-01-15T19:12:48","modified_gmt":"2025-01-15T11:12:48","slug":"%e5%a6%82%e4%bd%95%e8%b0%83%e6%95%b4python%e5%86%85%e5%ad%97%e5%8f%b7%e5%a4%a7%e5%b0%8f","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1183280.html","title":{"rendered":"\u5982\u4f55\u8c03\u6574python\u5185\u5b57\u53f7\u5927\u5c0f"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25133118\/8be04002-de0c-469a-b49b-c3e12bd31b7c.webp\" alt=\"\u5982\u4f55\u8c03\u6574python\u5185\u5b57\u53f7\u5927\u5c0f\" \/><\/p>\n<p><p> \u8c03\u6574Python\u5185\u5b57\u53f7\u5927\u5c0f\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec<strong>\u4f7f\u7528IDE\u6216\u6587\u672c\u7f16\u8f91\u5668\u7684\u8bbe\u7f6e\u3001\u4f7f\u7528GUI\u5e93\u5982Tkinter\u6216PyQt\u4fee\u6539\u5b57\u4f53\u5927\u5c0f\u3001\u5728Jupyter Notebook\u4e2d\u8c03\u6574Markdown\u548cCode Cell\u7684\u5b57\u4f53\u5927\u5c0f<\/strong>\u3002\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u53ef\u4ee5\u6709\u6548\u5730\u8c03\u6574Python\u5185\u7684\u5b57\u53f7\u5927\u5c0f\uff0c\u4ee5\u6ee1\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\u2014\u2014\u4f7f\u7528Tkinter\u5e93\u8c03\u6574\u5b57\u4f53\u5927\u5c0f\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001IDE\u6216\u6587\u672c\u7f16\u8f91\u5668\u8bbe\u7f6e<\/h2>\n<\/p>\n<p><h3>1\u3001PyCharm<\/h3>\n<\/p>\n<p><p>PyCharm\u662f\u4e00\u4e2a\u6d41\u884c\u7684Python IDE\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u6765\u8c03\u6574\u4ee3\u7801\u5b57\u4f53\u7684\u5927\u5c0f\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00PyCharm\uff0c\u8fdb\u5165Settings\uff08\u8bbe\u7f6e\uff09\u3002<\/li>\n<li>\u5728\u5de6\u4fa7\u83dc\u5355\u4e2d\u627e\u5230Editor\uff08\u7f16\u8f91\u5668\uff09\uff0c\u7136\u540e\u9009\u62e9Font\uff08\u5b57\u4f53\uff09\u3002<\/li>\n<li>\u5728\u8fd9\u91cc\u4f60\u53ef\u4ee5\u8c03\u6574\u5b57\u4f53\u7684\u540d\u79f0\u3001\u5927\u5c0f\u548c\u884c\u95f4\u8ddd\u7b49\u5c5e\u6027\u3002<\/li>\n<\/ul>\n<p><h3>2\u3001VS Code<\/h3>\n<\/p>\n<p><p>VS Code\u662f\u53e6\u4e00\u4e2a\u5e7f\u6cdb\u4f7f\u7528\u7684\u7f16\u8f91\u5668\uff0c\u5176\u5b57\u4f53\u5927\u5c0f\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8c03\u6574\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00VS Code\uff0c\u8fdb\u5165Settings\uff08\u8bbe\u7f6e\uff09\u3002<\/li>\n<li>\u5728\u641c\u7d22\u680f\u4e2d\u8f93\u5165\u201cFont Size\u201d\u3002<\/li>\n<li>\u627e\u5230\u201cEditor: Font Size\u201d\uff0c\u8c03\u6574\u5176\u6570\u503c\u5373\u53ef\u66f4\u6539\u5b57\u4f53\u5927\u5c0f\u3002<\/li>\n<\/ul>\n<p><h3>3\u3001Jupyter Notebook<\/h3>\n<\/p>\n<p><p>\u5728Jupyter Notebook\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u914d\u7f6e\u6587\u4ef6\u6216\u4f7f\u7528\u81ea\u5b9a\u4e49CSS\u6765\u6539\u53d8\u5b57\u4f53\u5927\u5c0f\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00Jupyter Notebook\u3002<\/li>\n<li>\u8fdb\u5165\u201cView\u201d\u83dc\u5355\uff0c\u9009\u62e9\u201cCell Toolbar\u201d\uff0c\u7136\u540e\u9009\u62e9\u201cEdit Metadata\u201d\u3002<\/li>\n<li>\u5728\u5f39\u51fa\u7684JSON\u914d\u7f6e\u4e2d\uff0c\u53ef\u4ee5\u6dfb\u52a0\u81ea\u5b9a\u4e49CSS\u6765\u4fee\u6539\u5b57\u4f53\u5927\u5c0f\u3002<\/li>\n<\/ul>\n<p><h2>\u4e8c\u3001\u4f7f\u7528Tkinter\u5e93\u8c03\u6574\u5b57\u4f53\u5927\u5c0f<\/h2>\n<\/p>\n<p><p>Tkinter\u662fPython\u7684\u6807\u51c6GUI\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u521b\u5efa\u7a97\u53e3\u548c\u7ba1\u7406\u63a7\u4ef6\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Tkinter\u8c03\u6574\u5b57\u4f53\u5927\u5c0f\u7684\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tkinter as tk<\/p>\n<p>from tkinter import font<\/p>\n<h2><strong>\u521b\u5efa\u4e3b\u7a97\u53e3<\/strong><\/h2>\n<p>root = tk.Tk()<\/p>\n<p>root.title(&quot;Tkinter Font Size Example&quot;)<\/p>\n<h2><strong>\u521b\u5efa\u5b57\u4f53\u5bf9\u8c61\u5e76\u8bbe\u7f6e\u5927\u5c0f<\/strong><\/h2>\n<p>custom_font = font.Font(family=&quot;Helvetica&quot;, size=16)<\/p>\n<h2><strong>\u521b\u5efa\u6807\u7b7e\u5e76\u5e94\u7528\u81ea\u5b9a\u4e49\u5b57\u4f53<\/strong><\/h2>\n<p>label = tk.Label(root, text=&quot;Hello, Tkinter!&quot;, font=custom_font)<\/p>\n<p>label.pack(pady=20)<\/p>\n<h2><strong>\u8fd0\u884c\u4e3b\u5faa\u73af<\/strong><\/h2>\n<p>root.m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>nloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165\u4e86<code>tkinter<\/code>\u548c<code>font<\/code>\u6a21\u5757\uff0c\u7136\u540e\u521b\u5efa\u4e86\u4e00\u4e2a\u4e3b\u7a97\u53e3\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u81ea\u5b9a\u4e49\u5b57\u4f53\u5bf9\u8c61\uff0c\u5e76\u5c06\u5176\u5e94\u7528\u5230\u6807\u7b7e\u63a7\u4ef6\u4e2d\u3002\u6700\u540e\uff0c\u6211\u4eec\u8fd0\u884c\u4e3b\u5faa\u73af\u6765\u663e\u793a\u7a97\u53e3\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528PyQt\u5e93\u8c03\u6574\u5b57\u4f53\u5927\u5c0f<\/h2>\n<\/p>\n<p><p>PyQt\u662f\u53e6\u4e00\u4e2a\u6d41\u884c\u7684Python GUI\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u521b\u5efa\u66f4\u52a0\u590d\u6742\u7684\u7528\u6237\u754c\u9762\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528PyQt\u8c03\u6574\u5b57\u4f53\u5927\u5c0f\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PyQt5 import QtWidgets, QtGui<\/p>\n<h2><strong>\u521b\u5efa\u5e94\u7528\u7a0b\u5e8f\u5bf9\u8c61<\/strong><\/h2>\n<p>app = QtWidgets.QApplication([])<\/p>\n<h2><strong>\u521b\u5efa\u4e3b\u7a97\u53e3<\/strong><\/h2>\n<p>window = QtWidgets.QWidget()<\/p>\n<p>window.setWindowTitle(&quot;PyQt Font Size Example&quot;)<\/p>\n<h2><strong>\u521b\u5efa\u5b57\u4f53\u5bf9\u8c61\u5e76\u8bbe\u7f6e\u5927\u5c0f<\/strong><\/h2>\n<p>font = QtGui.QFont(&quot;Helvetica&quot;, 16)<\/p>\n<h2><strong>\u521b\u5efa\u6807\u7b7e\u5e76\u5e94\u7528\u81ea\u5b9a\u4e49\u5b57\u4f53<\/strong><\/h2>\n<p>label = QtWidgets.QLabel(&quot;Hello, PyQt!&quot;, window)<\/p>\n<p>label.setFont(font)<\/p>\n<p>label.move(50, 50)<\/p>\n<h2><strong>\u663e\u793a\u7a97\u53e3<\/strong><\/h2>\n<p>window.show()<\/p>\n<h2><strong>\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f<\/strong><\/h2>\n<p>app.exec_()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165\u4e86<code>QtWidgets<\/code>\u548c<code>QtGui<\/code>\u6a21\u5757\uff0c\u7136\u540e\u521b\u5efa\u4e86\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u5bf9\u8c61\u548c\u4e3b\u7a97\u53e3\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u81ea\u5b9a\u4e49\u5b57\u4f53\u5bf9\u8c61\uff0c\u5e76\u5c06\u5176\u5e94\u7528\u5230\u6807\u7b7e\u63a7\u4ef6\u4e2d\u3002\u6700\u540e\uff0c\u6211\u4eec\u663e\u793a\u7a97\u53e3\u5e76\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001Jupyter Notebook\u8c03\u6574\u5b57\u4f53\u5927\u5c0f<\/h2>\n<\/p>\n<p><p>\u5728Jupyter Notebook\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u81ea\u5b9a\u4e49CSS\u6765\u8c03\u6574Markdown\u548cCode Cell\u7684\u5b57\u4f53\u5927\u5c0f\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><h3>1\u3001\u4fee\u6539Markdown Cell\u5b57\u4f53\u5927\u5c0f<\/h3>\n<\/p>\n<p><p>\u5728Markdown Cell\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528HTML\u6807\u7b7e\u6765\u4fee\u6539\u5b57\u4f53\u5927\u5c0f\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-markdown\">&lt;div style=&quot;font-size:20px;&quot;&gt;This is a larger font size for Markdown cell.&lt;\/div&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u4fee\u6539Code Cell\u5b57\u4f53\u5927\u5c0f<\/h3>\n<\/p>\n<p><p>\u8981\u4fee\u6539Code Cell\u7684\u5b57\u4f53\u5927\u5c0f\uff0c\u53ef\u4ee5\u901a\u8fc7\u81ea\u5b9a\u4e49CSS\u6587\u4ef6\u6765\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>custom.css<\/code>\u7684\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u653e\u7f6e\u5728Jupyter\u7684\u914d\u7f6e\u76ee\u5f55\u4e2d\uff08\u901a\u5e38\u662f<code>~\/.jupyter\/custom\/<\/code>\uff09\u3002<\/li>\n<li>\u5728<code>custom.css<\/code>\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0bCSS\u89c4\u5219\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-css\">.CodeMirror pre {<\/p>\n<p>    font-size: 16px;<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li>\u91cd\u542fJupyter Notebook\uff0c\u4f7f\u66f4\u6539\u751f\u6548\u3002<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u8c03\u6574Python\u5185\u7684\u5b57\u53f7\u5927\u5c0f\uff0c\u4ece\u800c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u7528\u6237\u4f53\u9a8c\u3002\u4e0d\u540c\u7684\u65b9\u6cd5\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u573a\u666f\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u6539\u53d8\u6587\u672c\u7684\u5b57\u53f7\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u6539\u53d8\u6587\u672c\u7684\u5b57\u53f7\u901a\u5e38\u4f9d\u8d56\u4e8e\u6240\u4f7f\u7528\u7684\u5e93\u3002\u4f8b\u5982\uff0c\u5728\u4f7f\u7528Matplotlib\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>fontsize<\/code>\u53c2\u6570\u6765\u8c03\u6574\u56fe\u8868\u4e2d\u7684\u6587\u672c\u5b57\u53f7\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt\n\nplt.title(&quot;\u6807\u9898&quot;, fontsize=20)\nplt.xlabel(&quot;X\u8f74&quot;, fontsize=14)\nplt.ylabel(&quot;Y\u8f74&quot;, fontsize=14)\nplt.show()\n<\/code><\/pre>\n<p>\u5bf9\u4e8eTkinter GUI\u5e94\u7528\uff0c\u53ef\u4ee5\u901a\u8fc7<code>font<\/code>\u6a21\u5757\u8bbe\u7f6e\u5b57\u4f53\u548c\u5b57\u53f7\uff0c\u5982\u4e0b\u6240\u793a\uff1a  <\/p>\n<pre><code class=\"language-python\">import tkinter as tk\nfrom tkinter import font\n\nroot = tk.Tk()\nmy_font = font.Font(size=20)\nlabel = tk.Label(root, text=&quot;Hello, World!&quot;, font=my_font)\nlabel.pack()\nroot.mainloop()\n<\/code><\/pre>\n<p><strong>\u5728Jupyter Notebook\u4e2d\u5982\u4f55\u8c03\u6574\u5b57\u53f7\uff1f<\/strong><br \/>\u5728Jupyter Notebook\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528HTML\u548cMarkdown\u6765\u8c03\u6574\u5b57\u4f53\u5927\u5c0f\u3002\u901a\u8fc7\u4f7f\u7528<code>&lt;h1&gt;<\/code>\u81f3<code>&lt;h6&gt;<\/code>\u6807\u7b7e\u53ef\u4ee5\u8bbe\u7f6e\u4e0d\u540c\u7684\u5b57\u53f7\uff0c\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-markdown\"># \u8fd9\u662f\u4e00\u4e2a\u5927\u6807\u9898\n## \u8fd9\u662f\u4e00\u4e2a\u4e2d\u7b49\u5927\u5c0f\u7684\u6807\u9898\n### \u8fd9\u662f\u4e00\u4e2a\u5c0f\u6807\u9898\n<\/code><\/pre>\n<p>\u6b64\u5916\uff0c\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528<code>IPython.display<\/code>\u5e93\u6765\u8bbe\u7f6e\u7279\u5b9a\u7684\u5b57\u53f7\uff1a  <\/p>\n<pre><code class=\"language-python\">from IPython.display import display, HTML\n\ndisplay(HTML(&quot;&lt;h1 style=&#39;font-size:30px;&#39;&gt;\u5927\u6807\u9898&lt;\/h1&gt;&quot;))\n<\/code><\/pre>\n<p><strong>\u8c03\u6574Python\u811a\u672c\u4e2d\u6253\u5370\u6587\u672c\u7684\u5b57\u53f7\u7684\u65b9\u6cd5\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u5728\u6807\u51c6\u7684Python\u811a\u672c\u4e2d\uff0c\u63a7\u5236\u6253\u5370\u8f93\u51fa\u7684\u5b57\u53f7\u901a\u5e38\u662f\u901a\u8fc7\u7ec8\u7aef\u6216\u547d\u4ee4\u884c\u5de5\u5177\u7684\u8bbe\u7f6e\u6765\u5b9e\u73b0\u7684\u3002\u5982\u679c\u60a8\u5e0c\u671b\u5728\u7ec8\u7aef\u4e2d\u663e\u793a\u66f4\u5927\u5b57\u53f7\uff0c\u53ef\u4ee5\u8c03\u6574\u7ec8\u7aef\u7684\u5b57\u4f53\u8bbe\u7f6e\uff0c\u4f8b\u5982\u5728Windows\u6216Linux\u4e2d\u66f4\u6539\u7ec8\u7aef\u7684\u5b57\u4f53\u5927\u5c0f\u3002\u5bf9\u4e8eGUI\u7a0b\u5e8f\uff0c\u4f7f\u7528\u76f8\u5173GUI\u5e93\uff08\u5982Tkinter\u3001PyQt\u7b49\uff09\u53ef\u4ee5\u76f4\u63a5\u5728\u4ee3\u7801\u4e2d\u8bbe\u7f6e\u5b57\u53f7\u3002\u5982\u524d\u9762\u6240\u8ff0\uff0c\u53ef\u4ee5\u901a\u8fc7<code>font<\/code>\u6a21\u5757\u6216<code>QFont<\/code>\u7c7b\u6765\u5b9e\u73b0\u5b57\u4f53\u5927\u5c0f\u7684\u8c03\u6574\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8c03\u6574Python\u5185\u5b57\u53f7\u5927\u5c0f\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528IDE\u6216\u6587\u672c\u7f16\u8f91\u5668\u7684\u8bbe\u7f6e\u3001\u4f7f\u7528GUI\u5e93\u5982Tkinter\u6216PyQ [&hellip;]","protected":false},"author":3,"featured_media":1183286,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1183280"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1183280"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1183280\/revisions"}],"predecessor-version":[{"id":1183288,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1183280\/revisions\/1183288"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1183286"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1183280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1183280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1183280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}