Python Forum

Full Version: which button should be shown
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
suppose we have a lot of buttons with specified texts & locations... for example our buttons are {'main','report', 'memory', 'bills',...} now we have an array that determine which button should be visible for example z1=['report', 'bills'] the contents of this array can be the other buttons in your oponions, how can i write the code? should i compare the text of every button with "z1" array, before defining every button this is not reasonable,because the numbers of buttons are alot please helppppppp   Confused
this is mu code

[ z1=['report','bills','setting']


       self.button = Button(self.master,text="memory", command=self.ouvrir)

        self.button.grid(row=1, column=1)

        

        self.button2 = Button(self.master,text="report", command=self.tabluh)

        self.button2.grid(row=1, column=2)





        self.button3 = Button(self.master,text="setting", command=self.new_window)

        self.button3.grid(row=1, column=3)



        self.button4 = Button(self.master,text="calibration", command=self.cal)

        self.button4.grid(row=1, column=4)





        self.button5 = Button(self.master,text="empty weight", command=self.weighing)

        self.button5.grid(row=1, column=5)



        self.button6 = Button(self.master,text="bills", command=self.history)

        self.button6.grid(row=1, column=6) 



        self.button7 = Button(self.master,text="full weight", command=self.full)
        self.button7.grid(row=1, column=7)]
[/python]
Moderator Larz60+: Added python tags. please do so in the future. indentation seems incorrect
You are not showing complete code.
Which GUI are you using? (looks like tkinter)
if so, you should see all of the buttons on same row. (after fixing indentation)

you can use state to grey out a button (still visible)
of put them all in same position (same row, column for each)(using frame) and lift the one you want visible

I have an example for this (for text widget, should work for buttons), see: https://github.com/Larz60p/PyHarry/blob/...arryGui.py
look at methods show_texwin and hide_texwin.
To work properly, all items in the stack must be at the same physical location in the window.