Python Forum
which button should be shown
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
which button should be shown
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] main GUI is not shown flash77 3 382 Feb-20-2024, 05:27 PM
Last Post: flash77
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 4,947 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020