【发布时间】:2015-07-07 16:34:14
【问题描述】:
有没有办法确保按钮缩小以适合 tkinter 框架。
这是我的代码。
import tkinter as tk
import dashboard as da
from 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()
您看到的图像是 100X100 png 图像。
问题是,当框架出现时,最后两个按钮没有出现在框架中。如果我调整整个窗口的大小,底部的按钮不会出现。有没有办法在主窗口调整大小时动态调整按钮大小。 尝试使用 google 提供所有可用选项,例如 pack.propagate 等,但它似乎对我不起作用。
【问题讨论】:
标签: python button tkinter autoresize