Disco Dancefloor Mini-Game

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
5
down vote
favorite
I was told to have my code reviewed here as I am a total beginner to Python.
I made a small Tkinter script that generates a 4x4 field of buttons and randomly recolors them when clicking on any button, but I was told that the code is not clean. If someone could point out a few flaws and some possible enhancements that would relly help a lot.
from tkinter import *
from random import randint
window = Tk()
window.title("Test")
window.geometry('200x200')
color = ["red","blue","green","yellow","black","purple","orange"]
RandInt = 0
j = 0
h = 0
def ButtonDef(xvar = 0,yvar = 0):
btn = Button(window,command =lambda:[RandomColor()])
btn.grid()
btn.place(x = xvar*50, y = yvar*50, width = 50, height = 50)
def RandomColor():
for child in window.winfo_children():
child.configure(bg=color[randint(0,6)])
while j in range (4):
i = 0
j += 1
while i in range (4):
ButtonDef(i,h)
i += 1
if i == 4:
h += 1
window.mainloop()
python beginner tkinter
add a comment |Â
up vote
5
down vote
favorite
I was told to have my code reviewed here as I am a total beginner to Python.
I made a small Tkinter script that generates a 4x4 field of buttons and randomly recolors them when clicking on any button, but I was told that the code is not clean. If someone could point out a few flaws and some possible enhancements that would relly help a lot.
from tkinter import *
from random import randint
window = Tk()
window.title("Test")
window.geometry('200x200')
color = ["red","blue","green","yellow","black","purple","orange"]
RandInt = 0
j = 0
h = 0
def ButtonDef(xvar = 0,yvar = 0):
btn = Button(window,command =lambda:[RandomColor()])
btn.grid()
btn.place(x = xvar*50, y = yvar*50, width = 50, height = 50)
def RandomColor():
for child in window.winfo_children():
child.configure(bg=color[randint(0,6)])
while j in range (4):
i = 0
j += 1
while i in range (4):
ButtonDef(i,h)
i += 1
if i == 4:
h += 1
window.mainloop()
python beginner tkinter
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I was told to have my code reviewed here as I am a total beginner to Python.
I made a small Tkinter script that generates a 4x4 field of buttons and randomly recolors them when clicking on any button, but I was told that the code is not clean. If someone could point out a few flaws and some possible enhancements that would relly help a lot.
from tkinter import *
from random import randint
window = Tk()
window.title("Test")
window.geometry('200x200')
color = ["red","blue","green","yellow","black","purple","orange"]
RandInt = 0
j = 0
h = 0
def ButtonDef(xvar = 0,yvar = 0):
btn = Button(window,command =lambda:[RandomColor()])
btn.grid()
btn.place(x = xvar*50, y = yvar*50, width = 50, height = 50)
def RandomColor():
for child in window.winfo_children():
child.configure(bg=color[randint(0,6)])
while j in range (4):
i = 0
j += 1
while i in range (4):
ButtonDef(i,h)
i += 1
if i == 4:
h += 1
window.mainloop()
python beginner tkinter
I was told to have my code reviewed here as I am a total beginner to Python.
I made a small Tkinter script that generates a 4x4 field of buttons and randomly recolors them when clicking on any button, but I was told that the code is not clean. If someone could point out a few flaws and some possible enhancements that would relly help a lot.
from tkinter import *
from random import randint
window = Tk()
window.title("Test")
window.geometry('200x200')
color = ["red","blue","green","yellow","black","purple","orange"]
RandInt = 0
j = 0
h = 0
def ButtonDef(xvar = 0,yvar = 0):
btn = Button(window,command =lambda:[RandomColor()])
btn.grid()
btn.place(x = xvar*50, y = yvar*50, width = 50, height = 50)
def RandomColor():
for child in window.winfo_children():
child.configure(bg=color[randint(0,6)])
while j in range (4):
i = 0
j += 1
while i in range (4):
ButtonDef(i,h)
i += 1
if i == 4:
h += 1
window.mainloop()
python beginner tkinter
edited May 15 at 10:08
yuri
3,3852832
3,3852832
asked May 15 at 10:04
Flying Thunder
454
454
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
One of the first useful things to take in consideration when developing in Python (whether you are a beginner or expert) is the PEP 8 that provides general rules how to write a code that can help other developers to read your code.
- For example, from the naming conventions section you can read that variable names are written in snake_camel case. This means
RandIntshould be re-written asrand_intandButtonDef()RandomColor()should be writtenbutton_def()andrandom_color()respectively. - In the imports section, you can read that we should avoid wild card imports. This means we should write
import tkinter as tkinstead offrom tkinter import *
- For example, from the naming conventions section you can read that variable names are written in snake_camel case. This means
- Names should be meaningful and express their purpose. This means
ButtonDef(), which is rather a misleading name, could be namedcreate_buttons()instead because you are creating 16 button widgets with that function. I would also renameRandomColor()by something likeget_random_color()orpick_random_color()because a function does something, so it is better the name gets prefixed with a verb. Also,coloris actually referencing several colors, so it should be namedcolorsinstead or, why not,colors_listbecause it consists of a list of colors. General code formatting rules:
- When affecting a value to a variable, we should leave one space character around both sides of the affectation symbol
=. But this does not apply to tkinter when it comes to a widget's argument. Let me take an example to clarify this:btn = Button(window,command =lambda:[RandomColor()])should be writtenbtn = Button(window,command=lambda:[RandomColor()])(changed...command =lambda:...to...command=lambda:...) - In this line:
while j in range (4):we should remove the space inrange (4):and writerange(4):instead.
- When affecting a value to a variable, we should leave one space character around both sides of the affectation symbol
There are two main suggestions:
- I would write your code in an OOP approach. No wonder that OOP and GUI coincided in birth historically.
- Ideally, whenever we create widgets, we would keep a reference to them for later reuse or code invocation. In your code,
btnis overridden several 16 times so, by the end, it refers only to the last created button widget; this means you can not access easily ([winfo_children()][3]offers a way to access the child widgets of window but it is hard to have a friendly control on them)
When you have to deal with several widgets and manage them through different lines and columns,
grid()will make your life much easier thanplace().
Based on all the elements previously mentioned, and based on tkinter best practices article, I would re-rewrite your code as follows:
import tkinter as tk
import random
class ChangeButtonsColor(tk.Frame):
def __init__(self, master):
self.master = master
tk.Frame.__init__(self, self.master)
self.__colors = ["red","blue","green","yellow","black","purple","orange"]
self.configure_gui()
self.create_widgets()
def configure_gui(self):
self.master.title('Test')
self.master.geometry('200x200')
def create_widgets(self):
self.create_buttons()
def create_buttons(self):
self.buttons =
for i in range(4):
for j in range(4):
self.buttons['button'.format(4*i + j)] = tk.Button(self.master, bg=self.get_random_color())
self.buttons['button'.format(4*i + j)].grid(row=i, column=j)
self.buttons['button'.format(4*i + j)].config(width=3, height=3)
self.buttons['button'.format(4*i + j)].config(command=self.change_buttons_color)
def get_random_color(self):
return random.choice(self.__colors)
def change_buttons_color(self):
for i in range(16):
self.buttons['button'.format(i)].config(bg=self.get_random_color())
if __name__ == '__main__':
root = tk.Tk()
main_app = ChangeButtonsColor(root)
root.mainloop()
Note that in I created a dictionary to keep references to each button I created in create_buttons() function. The way to access each button is demonstrated in change_buttons_color()
I heard about the OOA-OOD-OOP workflow, i think i should make a clear goal and see what i should do for that goal step by step - in this case, i just wrote whatever came to my mind because im kind of uncreative when it comes to creating something from scratch - im currently looking into the init and self stuff, i think thats what im not getting the most right now
â Flying Thunder
May 15 at 11:40
1
Storing buttons in a dict seems cumbersome at best, why not simply use a list and havechange_buttons_colorsimply dofor button in self.buttons: button.config(bg=self.get_random_color())? Same forcreate_buttons, why use an extra method on top ofcreate_widgets?
â Mathias Ettinger
May 15 at 12:36
Good note about the list. For the extra function you mentioned: in case the OP wants to enrich the GUI and create other areas of widgets, then he can add a corresponding suitable function name. When you have several components on the GUI and you know that you will have to configure them at least once, it is good to group related widgets in specific functions otherwise you get lost, I say this from my humble experience with tkinter @MathiasEttinger
â Billal BEGUERADJ
May 15 at 12:44
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
One of the first useful things to take in consideration when developing in Python (whether you are a beginner or expert) is the PEP 8 that provides general rules how to write a code that can help other developers to read your code.
- For example, from the naming conventions section you can read that variable names are written in snake_camel case. This means
RandIntshould be re-written asrand_intandButtonDef()RandomColor()should be writtenbutton_def()andrandom_color()respectively. - In the imports section, you can read that we should avoid wild card imports. This means we should write
import tkinter as tkinstead offrom tkinter import *
- For example, from the naming conventions section you can read that variable names are written in snake_camel case. This means
- Names should be meaningful and express their purpose. This means
ButtonDef(), which is rather a misleading name, could be namedcreate_buttons()instead because you are creating 16 button widgets with that function. I would also renameRandomColor()by something likeget_random_color()orpick_random_color()because a function does something, so it is better the name gets prefixed with a verb. Also,coloris actually referencing several colors, so it should be namedcolorsinstead or, why not,colors_listbecause it consists of a list of colors. General code formatting rules:
- When affecting a value to a variable, we should leave one space character around both sides of the affectation symbol
=. But this does not apply to tkinter when it comes to a widget's argument. Let me take an example to clarify this:btn = Button(window,command =lambda:[RandomColor()])should be writtenbtn = Button(window,command=lambda:[RandomColor()])(changed...command =lambda:...to...command=lambda:...) - In this line:
while j in range (4):we should remove the space inrange (4):and writerange(4):instead.
- When affecting a value to a variable, we should leave one space character around both sides of the affectation symbol
There are two main suggestions:
- I would write your code in an OOP approach. No wonder that OOP and GUI coincided in birth historically.
- Ideally, whenever we create widgets, we would keep a reference to them for later reuse or code invocation. In your code,
btnis overridden several 16 times so, by the end, it refers only to the last created button widget; this means you can not access easily ([winfo_children()][3]offers a way to access the child widgets of window but it is hard to have a friendly control on them)
When you have to deal with several widgets and manage them through different lines and columns,
grid()will make your life much easier thanplace().
Based on all the elements previously mentioned, and based on tkinter best practices article, I would re-rewrite your code as follows:
import tkinter as tk
import random
class ChangeButtonsColor(tk.Frame):
def __init__(self, master):
self.master = master
tk.Frame.__init__(self, self.master)
self.__colors = ["red","blue","green","yellow","black","purple","orange"]
self.configure_gui()
self.create_widgets()
def configure_gui(self):
self.master.title('Test')
self.master.geometry('200x200')
def create_widgets(self):
self.create_buttons()
def create_buttons(self):
self.buttons =
for i in range(4):
for j in range(4):
self.buttons['button'.format(4*i + j)] = tk.Button(self.master, bg=self.get_random_color())
self.buttons['button'.format(4*i + j)].grid(row=i, column=j)
self.buttons['button'.format(4*i + j)].config(width=3, height=3)
self.buttons['button'.format(4*i + j)].config(command=self.change_buttons_color)
def get_random_color(self):
return random.choice(self.__colors)
def change_buttons_color(self):
for i in range(16):
self.buttons['button'.format(i)].config(bg=self.get_random_color())
if __name__ == '__main__':
root = tk.Tk()
main_app = ChangeButtonsColor(root)
root.mainloop()
Note that in I created a dictionary to keep references to each button I created in create_buttons() function. The way to access each button is demonstrated in change_buttons_color()
I heard about the OOA-OOD-OOP workflow, i think i should make a clear goal and see what i should do for that goal step by step - in this case, i just wrote whatever came to my mind because im kind of uncreative when it comes to creating something from scratch - im currently looking into the init and self stuff, i think thats what im not getting the most right now
â Flying Thunder
May 15 at 11:40
1
Storing buttons in a dict seems cumbersome at best, why not simply use a list and havechange_buttons_colorsimply dofor button in self.buttons: button.config(bg=self.get_random_color())? Same forcreate_buttons, why use an extra method on top ofcreate_widgets?
â Mathias Ettinger
May 15 at 12:36
Good note about the list. For the extra function you mentioned: in case the OP wants to enrich the GUI and create other areas of widgets, then he can add a corresponding suitable function name. When you have several components on the GUI and you know that you will have to configure them at least once, it is good to group related widgets in specific functions otherwise you get lost, I say this from my humble experience with tkinter @MathiasEttinger
â Billal BEGUERADJ
May 15 at 12:44
add a comment |Â
up vote
3
down vote
accepted
One of the first useful things to take in consideration when developing in Python (whether you are a beginner or expert) is the PEP 8 that provides general rules how to write a code that can help other developers to read your code.
- For example, from the naming conventions section you can read that variable names are written in snake_camel case. This means
RandIntshould be re-written asrand_intandButtonDef()RandomColor()should be writtenbutton_def()andrandom_color()respectively. - In the imports section, you can read that we should avoid wild card imports. This means we should write
import tkinter as tkinstead offrom tkinter import *
- For example, from the naming conventions section you can read that variable names are written in snake_camel case. This means
- Names should be meaningful and express their purpose. This means
ButtonDef(), which is rather a misleading name, could be namedcreate_buttons()instead because you are creating 16 button widgets with that function. I would also renameRandomColor()by something likeget_random_color()orpick_random_color()because a function does something, so it is better the name gets prefixed with a verb. Also,coloris actually referencing several colors, so it should be namedcolorsinstead or, why not,colors_listbecause it consists of a list of colors. General code formatting rules:
- When affecting a value to a variable, we should leave one space character around both sides of the affectation symbol
=. But this does not apply to tkinter when it comes to a widget's argument. Let me take an example to clarify this:btn = Button(window,command =lambda:[RandomColor()])should be writtenbtn = Button(window,command=lambda:[RandomColor()])(changed...command =lambda:...to...command=lambda:...) - In this line:
while j in range (4):we should remove the space inrange (4):and writerange(4):instead.
- When affecting a value to a variable, we should leave one space character around both sides of the affectation symbol
There are two main suggestions:
- I would write your code in an OOP approach. No wonder that OOP and GUI coincided in birth historically.
- Ideally, whenever we create widgets, we would keep a reference to them for later reuse or code invocation. In your code,
btnis overridden several 16 times so, by the end, it refers only to the last created button widget; this means you can not access easily ([winfo_children()][3]offers a way to access the child widgets of window but it is hard to have a friendly control on them)
When you have to deal with several widgets and manage them through different lines and columns,
grid()will make your life much easier thanplace().
Based on all the elements previously mentioned, and based on tkinter best practices article, I would re-rewrite your code as follows:
import tkinter as tk
import random
class ChangeButtonsColor(tk.Frame):
def __init__(self, master):
self.master = master
tk.Frame.__init__(self, self.master)
self.__colors = ["red","blue","green","yellow","black","purple","orange"]
self.configure_gui()
self.create_widgets()
def configure_gui(self):
self.master.title('Test')
self.master.geometry('200x200')
def create_widgets(self):
self.create_buttons()
def create_buttons(self):
self.buttons =
for i in range(4):
for j in range(4):
self.buttons['button'.format(4*i + j)] = tk.Button(self.master, bg=self.get_random_color())
self.buttons['button'.format(4*i + j)].grid(row=i, column=j)
self.buttons['button'.format(4*i + j)].config(width=3, height=3)
self.buttons['button'.format(4*i + j)].config(command=self.change_buttons_color)
def get_random_color(self):
return random.choice(self.__colors)
def change_buttons_color(self):
for i in range(16):
self.buttons['button'.format(i)].config(bg=self.get_random_color())
if __name__ == '__main__':
root = tk.Tk()
main_app = ChangeButtonsColor(root)
root.mainloop()
Note that in I created a dictionary to keep references to each button I created in create_buttons() function. The way to access each button is demonstrated in change_buttons_color()
I heard about the OOA-OOD-OOP workflow, i think i should make a clear goal and see what i should do for that goal step by step - in this case, i just wrote whatever came to my mind because im kind of uncreative when it comes to creating something from scratch - im currently looking into the init and self stuff, i think thats what im not getting the most right now
â Flying Thunder
May 15 at 11:40
1
Storing buttons in a dict seems cumbersome at best, why not simply use a list and havechange_buttons_colorsimply dofor button in self.buttons: button.config(bg=self.get_random_color())? Same forcreate_buttons, why use an extra method on top ofcreate_widgets?
â Mathias Ettinger
May 15 at 12:36
Good note about the list. For the extra function you mentioned: in case the OP wants to enrich the GUI and create other areas of widgets, then he can add a corresponding suitable function name. When you have several components on the GUI and you know that you will have to configure them at least once, it is good to group related widgets in specific functions otherwise you get lost, I say this from my humble experience with tkinter @MathiasEttinger
â Billal BEGUERADJ
May 15 at 12:44
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
One of the first useful things to take in consideration when developing in Python (whether you are a beginner or expert) is the PEP 8 that provides general rules how to write a code that can help other developers to read your code.
- For example, from the naming conventions section you can read that variable names are written in snake_camel case. This means
RandIntshould be re-written asrand_intandButtonDef()RandomColor()should be writtenbutton_def()andrandom_color()respectively. - In the imports section, you can read that we should avoid wild card imports. This means we should write
import tkinter as tkinstead offrom tkinter import *
- For example, from the naming conventions section you can read that variable names are written in snake_camel case. This means
- Names should be meaningful and express their purpose. This means
ButtonDef(), which is rather a misleading name, could be namedcreate_buttons()instead because you are creating 16 button widgets with that function. I would also renameRandomColor()by something likeget_random_color()orpick_random_color()because a function does something, so it is better the name gets prefixed with a verb. Also,coloris actually referencing several colors, so it should be namedcolorsinstead or, why not,colors_listbecause it consists of a list of colors. General code formatting rules:
- When affecting a value to a variable, we should leave one space character around both sides of the affectation symbol
=. But this does not apply to tkinter when it comes to a widget's argument. Let me take an example to clarify this:btn = Button(window,command =lambda:[RandomColor()])should be writtenbtn = Button(window,command=lambda:[RandomColor()])(changed...command =lambda:...to...command=lambda:...) - In this line:
while j in range (4):we should remove the space inrange (4):and writerange(4):instead.
- When affecting a value to a variable, we should leave one space character around both sides of the affectation symbol
There are two main suggestions:
- I would write your code in an OOP approach. No wonder that OOP and GUI coincided in birth historically.
- Ideally, whenever we create widgets, we would keep a reference to them for later reuse or code invocation. In your code,
btnis overridden several 16 times so, by the end, it refers only to the last created button widget; this means you can not access easily ([winfo_children()][3]offers a way to access the child widgets of window but it is hard to have a friendly control on them)
When you have to deal with several widgets and manage them through different lines and columns,
grid()will make your life much easier thanplace().
Based on all the elements previously mentioned, and based on tkinter best practices article, I would re-rewrite your code as follows:
import tkinter as tk
import random
class ChangeButtonsColor(tk.Frame):
def __init__(self, master):
self.master = master
tk.Frame.__init__(self, self.master)
self.__colors = ["red","blue","green","yellow","black","purple","orange"]
self.configure_gui()
self.create_widgets()
def configure_gui(self):
self.master.title('Test')
self.master.geometry('200x200')
def create_widgets(self):
self.create_buttons()
def create_buttons(self):
self.buttons =
for i in range(4):
for j in range(4):
self.buttons['button'.format(4*i + j)] = tk.Button(self.master, bg=self.get_random_color())
self.buttons['button'.format(4*i + j)].grid(row=i, column=j)
self.buttons['button'.format(4*i + j)].config(width=3, height=3)
self.buttons['button'.format(4*i + j)].config(command=self.change_buttons_color)
def get_random_color(self):
return random.choice(self.__colors)
def change_buttons_color(self):
for i in range(16):
self.buttons['button'.format(i)].config(bg=self.get_random_color())
if __name__ == '__main__':
root = tk.Tk()
main_app = ChangeButtonsColor(root)
root.mainloop()
Note that in I created a dictionary to keep references to each button I created in create_buttons() function. The way to access each button is demonstrated in change_buttons_color()
One of the first useful things to take in consideration when developing in Python (whether you are a beginner or expert) is the PEP 8 that provides general rules how to write a code that can help other developers to read your code.
- For example, from the naming conventions section you can read that variable names are written in snake_camel case. This means
RandIntshould be re-written asrand_intandButtonDef()RandomColor()should be writtenbutton_def()andrandom_color()respectively. - In the imports section, you can read that we should avoid wild card imports. This means we should write
import tkinter as tkinstead offrom tkinter import *
- For example, from the naming conventions section you can read that variable names are written in snake_camel case. This means
- Names should be meaningful and express their purpose. This means
ButtonDef(), which is rather a misleading name, could be namedcreate_buttons()instead because you are creating 16 button widgets with that function. I would also renameRandomColor()by something likeget_random_color()orpick_random_color()because a function does something, so it is better the name gets prefixed with a verb. Also,coloris actually referencing several colors, so it should be namedcolorsinstead or, why not,colors_listbecause it consists of a list of colors. General code formatting rules:
- When affecting a value to a variable, we should leave one space character around both sides of the affectation symbol
=. But this does not apply to tkinter when it comes to a widget's argument. Let me take an example to clarify this:btn = Button(window,command =lambda:[RandomColor()])should be writtenbtn = Button(window,command=lambda:[RandomColor()])(changed...command =lambda:...to...command=lambda:...) - In this line:
while j in range (4):we should remove the space inrange (4):and writerange(4):instead.
- When affecting a value to a variable, we should leave one space character around both sides of the affectation symbol
There are two main suggestions:
- I would write your code in an OOP approach. No wonder that OOP and GUI coincided in birth historically.
- Ideally, whenever we create widgets, we would keep a reference to them for later reuse or code invocation. In your code,
btnis overridden several 16 times so, by the end, it refers only to the last created button widget; this means you can not access easily ([winfo_children()][3]offers a way to access the child widgets of window but it is hard to have a friendly control on them)
When you have to deal with several widgets and manage them through different lines and columns,
grid()will make your life much easier thanplace().
Based on all the elements previously mentioned, and based on tkinter best practices article, I would re-rewrite your code as follows:
import tkinter as tk
import random
class ChangeButtonsColor(tk.Frame):
def __init__(self, master):
self.master = master
tk.Frame.__init__(self, self.master)
self.__colors = ["red","blue","green","yellow","black","purple","orange"]
self.configure_gui()
self.create_widgets()
def configure_gui(self):
self.master.title('Test')
self.master.geometry('200x200')
def create_widgets(self):
self.create_buttons()
def create_buttons(self):
self.buttons =
for i in range(4):
for j in range(4):
self.buttons['button'.format(4*i + j)] = tk.Button(self.master, bg=self.get_random_color())
self.buttons['button'.format(4*i + j)].grid(row=i, column=j)
self.buttons['button'.format(4*i + j)].config(width=3, height=3)
self.buttons['button'.format(4*i + j)].config(command=self.change_buttons_color)
def get_random_color(self):
return random.choice(self.__colors)
def change_buttons_color(self):
for i in range(16):
self.buttons['button'.format(i)].config(bg=self.get_random_color())
if __name__ == '__main__':
root = tk.Tk()
main_app = ChangeButtonsColor(root)
root.mainloop()
Note that in I created a dictionary to keep references to each button I created in create_buttons() function. The way to access each button is demonstrated in change_buttons_color()
edited May 15 at 16:03
answered May 15 at 11:32
Billal BEGUERADJ
1
1
I heard about the OOA-OOD-OOP workflow, i think i should make a clear goal and see what i should do for that goal step by step - in this case, i just wrote whatever came to my mind because im kind of uncreative when it comes to creating something from scratch - im currently looking into the init and self stuff, i think thats what im not getting the most right now
â Flying Thunder
May 15 at 11:40
1
Storing buttons in a dict seems cumbersome at best, why not simply use a list and havechange_buttons_colorsimply dofor button in self.buttons: button.config(bg=self.get_random_color())? Same forcreate_buttons, why use an extra method on top ofcreate_widgets?
â Mathias Ettinger
May 15 at 12:36
Good note about the list. For the extra function you mentioned: in case the OP wants to enrich the GUI and create other areas of widgets, then he can add a corresponding suitable function name. When you have several components on the GUI and you know that you will have to configure them at least once, it is good to group related widgets in specific functions otherwise you get lost, I say this from my humble experience with tkinter @MathiasEttinger
â Billal BEGUERADJ
May 15 at 12:44
add a comment |Â
I heard about the OOA-OOD-OOP workflow, i think i should make a clear goal and see what i should do for that goal step by step - in this case, i just wrote whatever came to my mind because im kind of uncreative when it comes to creating something from scratch - im currently looking into the init and self stuff, i think thats what im not getting the most right now
â Flying Thunder
May 15 at 11:40
1
Storing buttons in a dict seems cumbersome at best, why not simply use a list and havechange_buttons_colorsimply dofor button in self.buttons: button.config(bg=self.get_random_color())? Same forcreate_buttons, why use an extra method on top ofcreate_widgets?
â Mathias Ettinger
May 15 at 12:36
Good note about the list. For the extra function you mentioned: in case the OP wants to enrich the GUI and create other areas of widgets, then he can add a corresponding suitable function name. When you have several components on the GUI and you know that you will have to configure them at least once, it is good to group related widgets in specific functions otherwise you get lost, I say this from my humble experience with tkinter @MathiasEttinger
â Billal BEGUERADJ
May 15 at 12:44
I heard about the OOA-OOD-OOP workflow, i think i should make a clear goal and see what i should do for that goal step by step - in this case, i just wrote whatever came to my mind because im kind of uncreative when it comes to creating something from scratch - im currently looking into the init and self stuff, i think thats what im not getting the most right now
â Flying Thunder
May 15 at 11:40
I heard about the OOA-OOD-OOP workflow, i think i should make a clear goal and see what i should do for that goal step by step - in this case, i just wrote whatever came to my mind because im kind of uncreative when it comes to creating something from scratch - im currently looking into the init and self stuff, i think thats what im not getting the most right now
â Flying Thunder
May 15 at 11:40
1
1
Storing buttons in a dict seems cumbersome at best, why not simply use a list and have
change_buttons_color simply do for button in self.buttons: button.config(bg=self.get_random_color())? Same for create_buttons, why use an extra method on top of create_widgets?â Mathias Ettinger
May 15 at 12:36
Storing buttons in a dict seems cumbersome at best, why not simply use a list and have
change_buttons_color simply do for button in self.buttons: button.config(bg=self.get_random_color())? Same for create_buttons, why use an extra method on top of create_widgets?â Mathias Ettinger
May 15 at 12:36
Good note about the list. For the extra function you mentioned: in case the OP wants to enrich the GUI and create other areas of widgets, then he can add a corresponding suitable function name. When you have several components on the GUI and you know that you will have to configure them at least once, it is good to group related widgets in specific functions otherwise you get lost, I say this from my humble experience with tkinter @MathiasEttinger
â Billal BEGUERADJ
May 15 at 12:44
Good note about the list. For the extra function you mentioned: in case the OP wants to enrich the GUI and create other areas of widgets, then he can add a corresponding suitable function name. When you have several components on the GUI and you know that you will have to configure them at least once, it is good to group related widgets in specific functions otherwise you get lost, I say this from my humble experience with tkinter @MathiasEttinger
â Billal BEGUERADJ
May 15 at 12:44
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f194443%2fdisco-dancefloor-mini-game%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password