I'm doing a game with tkinter and i need to allow the player to place buildings with the information of the x, the y and the orientation. I created this function :
def pageChoice():
fenetre = Tk()
fenetre['bg']='white'
fenetre.title("Choose the position of your building")
fenetre.geometry("500x600")
Frame1 = Frame(fenetre, borderwidth=2, relief=GROOVE)
Label(Frame1, text="choose the orientation of your building").pack(padx=10, pady=10)
Frame1.pack(padx=30, pady=30)
value=StringVar()
orientation = IntVar()
radiobutton_1 = Radiobutton(Frame1, text="Horizontal", variable=orientation, value=1)
radiobutton_1.pack()
radiobutton_2 = Radiobutton(Frame1, text="Vertical", variable=orientation, value=2)
radiobutton_2.pack()
Frame2 = Frame(fenetre, borderwidth=2, relief=GROOVE)
Label(Frame2, text="type the coordinates of the center of your building").pack(padx=5, pady=5)
Frame2.pack(padx=10, pady=10)
Frame3 = Frame(Frame2, borderwidth=2, relief=GROOVE)
Frame3['bg']='green'
Label(Frame3, text="as x").pack(padx=10, pady=10)
Frame3.pack(side=LEFT, padx=10, pady=30)
Frame4 = Frame(Frame2, borderwidth=2, relief=GROOVE)
Frame4['bg']='green'
Label(Frame4, text="as y").pack(padx=10, pady=10)
Frame4.pack(side=RIGHT, padx=10, pady=30)
entree1 = Text(Frame3, width=10, height=1)
entree1.pack()
entree2 = Text(Frame4, width=10, height=1)
entree2.pack()
def printInput():
ord = entree1.get(1.0, "end-1c")
abs = entree2.get(1.0, "end-1c")
print(ord, abs)
ori = orientation.get()
if ori == 1:
print('horizontal')
elif ori == 2:
print('vertical')
print(ori)
bouton = Button(fenetre, text="validate", relief = RAISED, command=printInput)
bouton.pack()
fenetre.mainloop()
print(pageChoix())
It works when I run it alone but when I call it with this other function, the radio button doesn't work and i cant get informations about the orientation :
MainJoueur1 = ['house','pool']
def Installation(L): # L is the list of buildings in inventory
fenetre = Tk()
fenetre.title("choose a building to place")
fenetre.geometry("140x90")
for i in range(len(L)):
bi = Button(fenetre, text =L[i], relief=RAISED, command = pageChoix).pack()
fenetre.mainloop()
print(Installation(MainJoueur1))
I don't get where is the problem, thanks for helping !