"""测试Label组件的基本用法,使用面向对象的方式"""
from tkinter import *
class Application(Frame):
"""一个经典的GUI程序的类的写法"""
def __init__(self, master=None):
super().__init__(master) # super()代表的父类的定义而不是父类对象
self.master = master
self.pack()
self.createWidget()
def createWidget(self):
"""创建组件"""
self.label01 = Label(self, text='百战程序员', width=10, Height=2,
bg='black', fg='white')
self.label01.pack()
self.label02 = Label(self, text='高淇老师', width=10, Height=2,
bg='blue', fg='white', font=('黑体', 30))
self.label02.pack()
# 显示图像
global photo # 把global声明成全局变量
photo = PhotoImage(file='imgs/logo.gif')
self.label03 = Label(self, image=photo)
self.label03.pack()
# 显示多行文本
self.label04 = Label(self, text='北京尚学堂\n百战程序员\n老高真帅',
borderwidth=1, relief='solid', justify='right')
self.label04.pack()
if __name__ == '__main__':
root = Tk()
root.geometry('400x240+200+300')
app = Application(master=root)
root.mainloop()
老师帮忙看下哪里有问题