我试图使标签颜色随机我尝试了底部的代码,但它不起作用。颜色为红绿蓝黄橙白青紫。如何使它显示为单色?
colors = ['red', 'green', 'blue', 'yellow', 'orange', 'white', 'cyan', 'purple']
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent, background="white")
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("Credits")
self.pack(fill=BOTH, expand=1)
label1 = Label(self, text="Code by blaba, fg=colors, bg=colors)
label1.pack()
label2 = Label(self, text="Idea by noctize", fg=colors, bg=colors)
label2.pack()
label3 = Label(self, text="Packed using py2exe", fg=colors, bg=colors)
label3.pack()
colorbutton = Button
quitButton = Button(self, text="Quit",
command=self.quit)
quitButton.place(x=50, y=70)
def main():
root = Tk()
root.geometry("250x150+300+300")
app = Example(root)
root.mainloop()
if __name__ == '__main__':
main()
怎么行不通?