python - tkinter buttons shrink to fit frame -
is there way ensure buttons shrink fit tkinter frame.
here code is.
import tkinter tk import dashboard da pil import image, imagetk class dashboard(): def __init__(self, root): global colors self.root=root root.title("natt server dashboard view") headerpanel = tk.frame(root, background=colors["grey2"], width=800, height=100) accountpanel = tk.frame(headerpanel, background=colors["grey3"], width=100, height=100) infopanel = tk.frame(headerpanel, background=colors["grey1"], bd=2, width=800, height=50) buttonpanel = tk.frame(root, background=colors["grey2"], width=100, height=700) canvaspanel = tk.frame(root, background=colors["white"], width=700, height=700) # pack these panels accountpanel.pack(side="left",fill="both") infopanel.pack(side="bottom", fill="x") headerpanel.pack(fill="x") canvaspanel.pack(side="right", fill="both", expand=true) buttonpanel.pack(side="left", fill="y") self._user_account(accountpanel) self._create_header(headerpanel) self._create_info_panel(infopanel) self._create_buttons(buttonpanel) self._create_canvas(canvaspanel) def _create_buttons(self, parent): #======================{{{ global colors img = image.open("icons/server-status-icon-100x100.png") photo = imagetk.photoimage(img) b1=tk.button(parent, image=photo, bg=colors["grey1"], command=self._server_status) b1.image = photo b1.pack(side="top", anchor = "n") img = image.open("icons/application-icon-100x100.png") photo = imagetk.photoimage(img) b2=tk.button(parent, image=photo, bg=colors["grey1"], command=lambda: self._contents("black", "version.log")) b2.image = photo b2.pack(side="top", anchor = "n") img = image.open("icons/clean-up-icon-100x100.png") photo = imagetk.photoimage(img) b3=tk.button(parent, image=photo, bg=colors["grey1"], command=lambda: self._contents("black", "cleanup_03_07_2015_18_05_15.jag")) b3.image = photo b3.pack(side="top", anchor = "n") img = image.open("icons/log-display-icon-100x100.png") photo = imagetk.photoimage(img) b4=tk.button(parent, image=photo, bg=colors["grey1"], command=self._log_display) b4.image = photo b4.pack(side="top", anchor = "n") img = image.open("icons/link-status-icon-100x100.png") photo = imagetk.photoimage(img) b5=tk.button(parent, image=photo, bg=colors["grey1"], command=self._link_status) b5.image = photo b5.pack(side="top", anchor = "n") img = image.open("icons/defect-resolution-icon-100x100.png") photo = imagetk.photoimage(img) b6=tk.button(parent, image=photo, bg=colors["grey1"], command=lambda: self._contents("black", "version.log")) b6.image = photo b6.pack(side="top", anchor = "n") img = image.open("icons/app-process-icon-100x100.png") photo = imagetk.photoimage(img) b7=tk.button(parent, image=photo, bg=colors["grey1"], command=self._process_output) b7.image = photo b7.pack(side="top", anchor = "n") if __name__== '__main__': root=tk.tk() board=dashboard(root) root.mainloop() images see 100x100 png images.
the issue is, when frame appears last 2 buttons doesn't appear in frame. if resize complete window, buttons @ bottom doesn't appear. there way dynamically resize buttons when main window resize. tried google available options , e.g pack.propagate, , others, doesn't seem work me.
no, tkinter can't automatically shrink buttons fit inside frame. have manage of yourself. can, instance, add binding <configure> event of frame, gets called whenever frame changes size. can size of frame , iterate on children, doing whatever need things fit.
Comments
Post a Comment