# 用类封装后的hello world

from tkinter import *

# 定义类
class App:
    def __init__(self,master):

        # 创建一个Frame用于包含其他widget
        frame = Frame(master)
        frame.pack()

        # 创建一个Button
        self.button = Button(frame, # master widget
                text="QUIT", fg="red", command=frame.quit)
        self.button.pack(side=LEFT)

        self.hi_there = Button(frame, text="Hello",command=self.say_hi)
        self.hi_there.pack(side=LEFT)

    def say_hi(self):
        print("hi there,everyone!")

root = Tk()
app = App(root)
root.mainloop()

  

相关文章:

  • 2021-07-28
  • 2021-11-21
  • 2022-01-31
  • 2021-04-09
  • 2021-11-22
  • 2021-06-27
  • 2021-06-23
  • 2022-02-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2022-01-26
  • 2022-12-23
  • 2021-04-19
相关资源
相似解决方案