import tkinter as tk
from tkinter import messagebox, Frame
class Application(Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.createwidget()
def createwidget(self):
"""
label标签控件,可显示文本和位图;Button按钮控件,在程序中显示按钮(button也可以添加图片),button添加参数state='disabled'设置按钮为禁用状态
参数配置三种方法,第一种如self.button_login=tk.Button(self, text='登录', command=self.login)直接在括号中编辑
第二种如self.button_login['text']='登录'
第三种如self.button_login.config(fg='red',bg='green')
"""
global login_image
login_image = tk.PhotoImage(file='image/welcome.gif')
self.label_image = tk.Label(self, image=login_image)
# 通过布局管理器管理
self.label_image.pack()
# bg背景色;fg字体颜色;font字体格式(什么体、大小);width宽(单位字符);height高度
self.label_info = tk.Label(self, text='tkinter学习', width=13, height=2,
bg='green', fg='white', font=('黑体', 20))
self.label_info.pack()
# borderwidth边框宽度;relief 3d效果;justify左对齐或者右对齐
self.label_text = tk.Label(self, text='登录吧\n麻溜的', borderwidth=1, relief='solid', justify='right')
self.label_text.pack()
# command绑定事件;text按钮名称显示
self.button_login = tk.Button(self, text='登录', command=self.login)
self.button_login.pack()
def login(self):
pass
if __name__ == '__main__':
root = tk.Tk()
root.geometry('450x250+400+400')
root.title('登录页面')
app = Application(master=root)
root.mainloop()