• 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() :
    # This function is going to come first
    # If you write after all the code, you will not find it
    def _change_content() :
        var.set('sweet potato')

    root = Tk()

    # Two frames
    frame1 = Frame(root)
    frame2 = Frame(root)

    Only variables of this type are accepted if the text displayed by # Label changes
    var = StringVar()
    var.set("Seaweed")

    text_label = Label(frame1,
                       textvariable=var,
                       justify=LEFT
                       )
    text_label.pack()

    the_button = Button(frame2,
                        text='Next sentence',
                        command=_change_content  The function that is called when clicked
                        )
    the_button.pack()

    You can switch these two places, 2 first, 1 last.
    frame1.pack(padx=20, pady=20)
    frame2.pack(padx=40, pady=40)

    mainloop()


if __name__ == '__main__':
    main()

Copy the code

The results

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.