Tkinter界面美化:按钮布局和 Treeview 调整
为了使界面更加对称美观,可以调整按钮的位置和大小,使其在视觉上更加统一。同时,可以对treeview的宽度进行调整,使其与按钮在同一水平线上,使整个界面更加协调。例如:
button_open = tk.Button(self.master, text='打开文件', font=('Arial', 12), command=self.open_file, padx=10, pady=10)
button_open.grid(row=3, column=0, sticky='nsew', padx=5, pady=5)
button_other1 = tk.Button(self.master, text='数据预处理', font=('Arial', 12), bg='blue', fg='white', command=self.ok_window, padx=10, pady=10)
button_other1.grid(row=1, column=0, sticky='nsew', padx=5, pady=5)
button_other2 = tk.Button(self.master, text='跳转到别的界面2', font=('Arial', 12), bg='green', fg='white', padx=10, pady=10)
button_other2.grid(row=1, column=1, sticky='nsew', padx=5, pady=5)
button_other3 = tk.Button(self.master, text='跳转到别的界面3', font=('Arial', 12), bg='red', fg='white', command=self.hhh_Window, padx=10, pady=10)
button_other3.grid(row=1, column=2, sticky='nsew', padx=5, pady=5)
button_other4 = tk.Button(self.master, text='跳转到别的界面4', font=('Arial', 12), bg='yellow', fg='black', padx=10, pady=10)
button_other4.grid(row=1, column=3, sticky='nsew', padx=5, pady=5)
button_exit = tk.Button(self.master, text='退出', font=('Arial', 12), command=self.master.quit, padx=10, pady=10)
button_exit.grid(row=3, column=1, sticky='nsew', padx=5, pady=5)
# 设置treeview
columns = ('Name', 'Year', 'Kilometers Driven', 'Mileage', 'Engine', 'Power', 'Seats', 'Price')
self.tree = ttk.Treeview(self.master, columns=columns, show='headings', height=15, padding=10)
self.tree.column('#0', width=0, stretch=tk.NO)
for col in columns:
self.tree.heading(col, text=col)
vsb = ttk.Scrollbar(self.master, orient='vertical', command=self.tree.yview)
vsb.grid(row=3, column=3, rowspan=1, sticky='ns', padx=5, pady=5)
self.tree.configure(yscrollcommand=vsb.set)
self.tree.grid(row=3, column=2, rowspan=1, sticky='nsew', padx=5, pady=5)
self.master.grid_rowconfigure(2, weight=1)
self.master.grid_columnconfigure(2, weight=1)
此外,还可以对按钮的颜色、字体、大小等进行调整,使其更加美观。可以根据具体需求进行调整。
原文地址: https://www.cveoy.top/t/topic/owBy 著作权归作者所有。请勿转载和采集!