Python全系列 教程
3567个小节阅读:5931.8k
目录
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
Button(按钮)用来执行用户的单击操作。Button可以包含文本,也可以包含图像。按钮被单击后会自动调用对应事件绑定的方法。
【示例】Button按钮用法(文字、图片、事件)
xxxxxxxxxx
"""测试Button组件的基本用法,使用面向对象的方式"""
from tkinter import *
from tkinter import messagebox
class Application(Frame):
def __init__(self, master=None):
super().__init__(master) # super()代表的是父类的定义,而不是父类对象
self.master = master
self.pack()
self.createWidget()
def createWidget(self):
"""创建组件"""
self.btn01 = Button(root, text="登录",
width=6,height=3,anchor=NE,command=self.login)
self.btn01.pack()
global photo
photo = PhotoImage(file="https://www.itbaizhan.com/wiki/imgs/start.gif")
self.btn02 = Button(root, image=photo,command=self.login)
self.btn02.pack()
self.btn02.config(state="disabled") #设置按钮为禁用
def login(self):
messagebox.showinfo("尚学堂学习系统", "登录成功!欢迎开始学习!")
if __name__ == '__main__':
root = Tk()
root.geometry("400x130+200+300")
app = Application(master=root)
root.mainloop()
运行结果: