我定义了一个使用以下代码创建标签的方法
from tkinter import *
class LoginFrame(Frame):
def __init__(self, parent):
super(LoginFrame, self).__init__()
self.parent = parent
self.initUI()
# initialize the login screen UI
def initUI(self):
self.parent.title("Login Screen")
# Set up login frame properties
self.parent.title("Login Screen")
# create a background image
photo_bg = PhotoImage(file="building.gif")
building = self.make_label(self.parent, image=photo_bg)
# creating instruction label, where the error occurs
inst_lbl = self.make_label(self.parent, "Please login to continue")
def make_label(parent, caption=NONE, side=TOP, **options):
label = Label(parent, text=caption, **options)
if side is not TOP:
label.pack(side=side)
else:
label.pack()
return label
def main():
top = Tk()
app = LoginFrame(top)
top.mainloop()
if __name__ == '__main__':
main()
尝试运行代码时出错了,
_tkinter.TclError: bad side "Please login to continue": must be top, bottom, left, or right
我想知道如何解决这个问题?使用make_label
创建背景图像时没有错误。
答案 0 :(得分:1)
您对make_label
的定义缺少self
参数。您需要将其定义为:
def make_label(self, parent, ...):