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按钮控件,在程序中显示按钮
"""
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()
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()