toolbar_frame.pack(side='right', fill='y')bottom_frame.pack(side='bottom', fill='x')tk.Label(toolbar, text="当前选中:").pack(side=tk.LEFT, padx=0.02, pady=0.02)tk.Label(toolbar).pack(side=tk.LEFT, fill=tk.BOTH, expand=True)tk.Label(toolbar).pack(side=tk.LEFT, fill=tk.BOTH, expand=True)ttk.Button(toolbar, text="查詢", style='my.TButton', command=lambda: QueryWindow(tk.Toplevel(master))).pack( side=tk.LEFT, padx=0.02, pady=0.02)tk.Label(toolbar).pack(side=tk.LEFT, fill=tk.BOTH, expand=True) ttk.Button(toolbar, text="關閉", style='my.TButton', command=self.quit_app).pack(side=tk.LEFT, padx=0.02, pady=0.02) # 显示工具栏 toolbar.pack(side=tk.TOP, fill=tk.BOTH)self.canvas.pack(side=tk.LEFT, fill=tk.BOTH)self.scrollbar.pack(side=tk.LEFT, fill=tk.BOTH) self.panel_right.pack(side=tk.LEFT, fill=tk.BOTH, expand=True) input_frame.pack(side=tk.TOP, fill=tk.X, padx=0.05, pady=0.05)self.label1.pack(side=tk.LEFT, padx=0.02, pady=0.02)self.label2.pack(side=tk.LEFT, padx=0.02, pady=0.02)self.combobox2.pack(side=tk.LEFT, padx=0.02, pady=0.02)self.label3.pack(side=tk.LEFT, padx=0.02, pady=0.02)self.combobox3.pack(side=tk.LEFT, padx=0.02, pady=0.02) self.label5.pack(side=tk.LEFT, padx=0.02, pady=0.02)self.combobox5.pack(side=tk.LEFT, padx=0.05, pady=0.05)self.label6.pack(side=tk.LEFT, padx=0.05, pady=0.05)self.combobox6.pack(side=tk.LEFT, padx=0.05, pady=0.05)把這段代碼修改為grid的方法
时间: 2023-08-06 20:21:53 浏览: 181
把这段代码修改为grid的方法如下:
```python
toolbar_frame.grid(row=1, column=1, sticky='ns')
bottom_frame.grid(row=2, column=1, sticky='ew')
tk.Label(toolbar, text="当前选中:").grid(row=1, column=1, padx=5, pady=5, sticky='w')
tk.Label(toolbar).grid(row=1, column=2, padx=5, pady=5, sticky='we')
tk.Label(toolbar).grid(row=1, column=3, padx=5, pady=5, sticky='we')
ttk.Button(toolbar, text="查詢", style='my.TButton', command=lambda: QueryWindow(tk.Toplevel(master))).grid(row=1, column=4, padx=5, pady=5, sticky='e')
tk.Label(toolbar).grid(row=1, column=5, padx=5, pady=5, sticky='we')
ttk.Button(toolbar, text="關閉", style='my.TButton', command=self.quit_app).grid(row=1, column=6, padx=5, pady=5, sticky='e')
toolbar.grid_columnconfigure(2, weight=1)
toolbar.grid_columnconfigure(3, weight=1)
self.canvas.grid(row=1, column=1, sticky='nsew')
self.scrollbar.grid(row=1, column=2, sticky='ns')
self.panel_right.grid(row=1, column=3, sticky='nsew')
input_frame.grid(row=1, column=1, sticky='ew', padx=5, pady=5)
self.label1.grid(row=1, column=1, padx=5, pady=5, sticky='w')
self.label2.grid(row=1, column=2, padx=5, pady=5, sticky='w')
self.combobox2.grid(row=1, column=3, padx=5, pady=5, sticky='we')
self.label3.grid(row=1, column=4, padx=5, pady=5, sticky='w')
self.combobox3.grid(row=1, column=5, padx=5, pady=5, sticky='we')
self.label5.grid(row=2, column=1, padx=5, pady=5, sticky='w')
self.combobox5.grid(row=2, column=2, padx=5, pady=5, sticky='we')
self.label6.grid(row=2, column=3, padx=5, pady=5, sticky='w')
self.combobox6.grid(row=2, column=4, padx=5, pady=5, sticky='we')
```
请注意,这只是一个可能的解决方案,具体的排列方式可能需要根据您的需求进行调整。
阅读全文