• Python: 3.8.11
  • OS: Ubuntu Kylin 20.04
  • Conda: 4.10.1
  • PyCharm: 2021.1.3 (Community Edition)

code

@author: Date: 8/6/21 ""

from tkinter import *


def main() :
    root = Tk()  Note the case of Tk

    photo = PhotoImage(file='text_photoimage.png')
    the_label = Label(root,
                      text='Walk the Beginner's Mind',
                      justify=LEFT,  # Left-align the string
                      image=photo,
                      compound=CENTER,  # Blend mode, text is displayed directly above the image
                      font=("宋体".20),  # font and size
                      fg='white'  The foreground color is the font color
                      )

    the_label.pack()  This sentence is indispensable

    mainloop()


if __name__ == '__main__':
    main()


Copy the code

The results

Knowledge extension

  • Some common Chinese font libraries need to be manually installed.
  • Code running results in the “garden” word into a box, some software after the Chinese many boxes, you can check the Chinese font library.

The resources

  • Tkinter document

Learning to recommend

  • Python documentation – English
  • Python documentation – Chinese
  • Python code PEP
  • Google version of the Python specification
  • Python source code
  • Python PEP
  • Optimal kirin
  • The nuggets platform
  • Gitee platform


Python is open source, cross-platform, interpretive, and interactive, and worth learning. Python’s design philosophy: elegant, unambiguous, simple. Advocate one way, preferably only one way to do one thing. Guis can be created with PyQt5, PySide2, wxPython, PyGObject, wxWidgets, etc. Code should be written in accordance with specifications to facilitate communication and understanding. Every language has its own unique ideas. Beginners need to change their thinking, practice and accumulate.