Python-GUI编程测试

import tkinter as tk


class MainWindow():
  def __init__(self):
    pass
    # 创建主窗口
    self.window = tk.Tk()
    self.window.minsize(300, 300)
    self.window.title("示例")
    # 添加组件
    self.addComponents()

    # 进入消息循环
    self.window.mainloop()


  def addComponents(self):
    my_frame = tk.Frame(self.window)
    my_frame.pack(side=tk.TOP)

    # 创建按钮
    my_button = tk.Button(my_frame, text="点我")
    my_button.pack(side=tk.LEFT)

    # 创建Canvas
    my_canvas = tk.Canvas(my_frame, bg='white')
    my_canvas.create_rectangle(50, 50, 150, 150, outline='red', fill='blue', width=5)

    # 创建复选框
    my_apple = tk.Checkbutton(my_frame, text='苹果')
    my_apple.pack(side=tk.TOP)

    # 创建单行文本
    name = tk.Label(my_frame, text="姓名")
    name.pack(side=tk.LEFT)
    name_value = tk.Entry(my_frame, bd=5)
    name_value.pack(side=tk.RIGHT)


if __name__ == "__main__":
  MainWindow()

Python-GUI编程测试

上一篇:【InstantiationException】:tk.mybatis.mapper.provider.base.BaseInsertProvider


下一篇:tkinter界面卡死的解决办法