import tkinter
import random
class App(tkinter.Frame):
def __init__(self, master):
tkinter.Frame.__init__(self,master)
self.master=master
self.grid()
self.colors=(('blue', 'green', 'orange', 'red', 'yellow', 'Tan', 'Brown', 'light green'))
self.bttn1=tkinter.Button(self, text='Click Me!', bg=str(self.colors[1]),
command=self.change_color)
self.bttn2=tkinter.Button(self, text='Click Me!', bg=str(self.colors[0]),
command=self.change_color)
self.bttn3=tkinter.Button(self, text='Click Me!', bg=str(self.colors[1]),
command=self.change_color)
self.bttn4=tkinter.Button(self, text='Click Me!', bg=str(self.colors[2]),
command=self.change_color)
self.bttn5=tkinter.Button(self, text='Click Me!', bg=str(self.colors[3]),
command=self.change_color)
self.bttn1.grid(row = 2, column = 0, sticky = 'nw')
self.bttn2.grid(row = 2, column = 1, sticky = 'nw')
self.bttn3.grid(row = 2, column = 2, sticky = 'nw')
self.bttn4.grid(row = 2, column = 3, sticky = 'nw')
self.bttn5.grid(row = 2, column = 4, sticky = 'nw')
def change_color(self):
random.shuffle(colors)
if self.bttn_clicks + 1:
self.bttn1.configure(background=color)
if self.bttn_clicks + 2:
self.bttn2.configure(background=color)
if self.bttn_clicks + 3:
bself.bttn3.configure(background=color)
self.bttn4.configure(background=color)
self.bttn5.configure(background=color)
root=tkinter.Tk()
root.title('Color Button')
root.geometry('300x50')
app=App(root)
root.mainloop()
What I have tried:
1. I tried to use labels and random.shuffle.
2. then someone said to try and use Iterators(I might just be using it wrong because I am a beginner)
3. Now Im trying to use a string under a function.
I will take any soulotion even if It changes everything. I understand that I am a beginner and what I'm doing might not even be helping me.