Python3 tkinter基础 Button text,fg 按钮上显示的文字 文字的颜色

时间:2023-03-09 19:36:14
Python3 tkinter基础 Button text,fg 按钮上显示的文字 文字的颜色

  •        Python : 3.7.0
  •          OS : Ubuntu 18.04.1 LTS
  •         IDE : PyCharm 2018.2.4
  •       Conda : 4.5.11
  •    typesetting : Markdown

code

"""
@Author : 行初心
@Date : 18-10-1
@Blog : www.cnblogs.com/xingchuxin
@Gitee : gitee.com/zhichengjiu
"""
import tkinter as tk # 面向对象的编程思想
class APP:
def __init__(self, master):
self.frame = tk.Frame(master)
self.frame.pack() # 新建一个按钮 上面的显示:佛手柑 前景色(字体颜色):蓝色
self.hi_there = tk.Button(frame, text="佛手柑", fg="blue")
self.hi_there.pack() def main():
root = tk.Tk()
app = APP(root) root.mainloop() if __name__ == '__main__':
main()

result

Python3 tkinter基础 Button text,fg 按钮上显示的文字 文字的颜色

reference

  • [文档] docs.python.org/3/library/tkinter.html

resource

  • [文档] docs.python.org/3
  • [规范] www.python.org/dev/peps/pep-0008
  • [规范] zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules
  • [源码] www.python.org/downloads/source
  • [ PEP ] www.python.org/dev/peps
  • [平台] www.cnblogs.com
  • [平台] gitee.com


Python具有开源、跨平台、解释型和交互式等特性,值得学习。

Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。

GUI可以选择PyQt5、PySide2、wxPython、PyGObject、wxWidgets等进行创作。

代码的书写要遵守规范,这样有助于沟通和理解。

每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。