Hello I am using pydroid 3
I'm working in a mini project on my own to learn more about gui and python
It's a mind game the program will randomly choose a number up to 9 there are 9 buttons you need to remember the chosen button by system and press it and the program will choose another and you need to press those 2 in order and so on
Right now I am having trouble in the beginning, I saw somewhere someone used a loop to make a bunch of buttons at once I tried that in my own way but I have trouble with button names in command
This is the code:
from tkinter import*
window=Tk()
buttons=[1,2,3,4,5,6,7,8,9]
#we are going to have 9 buttons
tframe=Frame(window)
mframe=Frame(window)
bframe=Frame(window)
#buttons are going to be in these frames
tframe.pack(padx=150,pady=(150,0),fill='both')
mframe.pack(padx=150,fill='both')
bframe.pack(padx=150,pady=(0,150),fill='both')
moves=[1]
def move():
if int(name['text'])==moves[0]:
name.config(bg='lime')
name['state']='disable'
#this needs to be fixed
counter=0
for num in buttons:
name=str('btn'+str(buttons[counter]))
if num<4:
name=Button(tframe,text=buttons[counter],activebackground='cyan',command=move)
elif num>3 and num<7:
name=Button(mframe,text=buttons[counter],activebackground='cyan',command=move)
else:
name=Button(bframe,text=buttons[counter],activebackground='cyan',command=move)
name.pack(side='left',ipadx=100,ipady=100)
counter+=1
#this is the loop that makes all buttons for us and set them in they're own frames nicely
window.mainloop()
I have problem in move function
If the user pressed the button that have 1 as text the button is supposed to change background color to lime and get disabled
I don't know what is the problem the names of the buttons or something else I tried to config name and btn1 both not work