Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to get a fullscreen treeview in tkinter with a button underneath it

so im trying to show a treeview fullscreen on a raspberry pi touchscreen. the treeview would be populated with items my script reads from a csv file. when a line contains a specific item there would be an alarm (using the gpio pins). this all works, now there should be a button beneath the treeview to reset the alarm.

this is the code for the tkinter part of the script, the function of the reset button works, it just won’t show on my display. when i disable the treeview, the button appears,; so i suspect there should be an error in my coding of this component.

mainScreen=tk.Tk()
mainScreen.title("Meldingen")
mainScreen.overrideredirect(True)
mainScreen.geometry("{0}x{1}+0+0".format(mainScreen.winfo_screenwidth(), mainScreen.winfo_screenheight()))
mainScreen.resizable(width=False, height=False)
s=ttk.Style()
s.theme_use('clam')
s.configure('Treeview', rowheight=40)

header=["time","alarm","adress","message"]
tree=ttk.Treeview(mainScreen,columns=header, show="headings")
tree.pack(padx=20, pady=20,fill="x")
reset_button=tk.Button(mainScreen,text="reset alarm",command=reset_alarm,state= tk.DISABLED)
reset_button.pack(padx=20, pady=10)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It seems like you’re facing an issue where the reset _button is not appearing on the screen when the tree view is enabled.

One possible solution is to use the grid geometry manager instead of pack. This provides more control over widget placement.

Here’s your code modified to use ‘grid’:

tree. grid(row=0, column=0, pad x=20, pad y=20, sticky="ew")  # Use grid instead of pack

reset _button = tk. Button (main Screen, text="reset alarm", command=reset_ alarm, state=tk. DISABLED)
reset _button. grid(row=1, column=0, pad x=20, pad y=10, sticky="ew")  # Use grid instead of pack

main Screen .main loop()

With grid, you specify the row and column where each widget should be placed. The sticky parameter specifies how the widget should expand to fill the space allotted to it; "ew" means the widget should expand horizontally with the window. Adjust the row and column numbers as needed to achieve the desired layout.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading