我有问题。我使用的是tkinter和Python2.7。如何在调整窗口大小后更改小部件的长度?我有两个小部件:
条目1(列=0)和条目2(列=1)
入口1具有固定宽度。Entry2应该填充剩余的宽度。不幸的是,它不起作用。
有办法吗?
提前致谢。
代码:from Tkinter import *
import ttk
root = Tk()
root.grid_columnconfigure(0, weight=1)
root.grid_rowconfigure(0, weight=1)
notebook = ttk.Notebook(root)
tab = Frame(notebook)
notebook.add(tab, text = "Tab 1")
notebook.grid(row=0,column=0, sticky="NSEW")
tab.grid_columnconfigure(0, weight =1)
tab.grid_rowconfigure(0, weight=1)
canvas_tab = Canvas(tab, width=500, height=100)
scroll_tab = Scrollbar(tab, command = canvas_tab.yview)
canvas_tab.config(yscrollcommand=scroll_tab.set)
scroll_tab.grid(row=0, column = 1, sticky = "NSE")
canvas_tab.grid(row=0, column = 0, sticky = "NSEW")
canvas_tab.grid_columnconfigure(0, weight=1)
frame = Frame(canvas_tab)
frame.grid_columnconfigure(1, weight=1)
Entry1 = Entry(frame, text = "", width=20, justify = CENTER)
Entry1.grid(row = 0, column = 0)
Entry1.insert(0, 'Entry 1')
Entry2 = Entry(frame, text = "", justify = CENTER)
Entry2.grid(row = 0, column = 1, sticky = "NSEW")
Entry2.insert(0, 'Entry 2')
def configure(event):
canvas_tab.itemconfig(root, width=event.width)
canvas_tab.create_window((0,0), anchor=NW, window=frame)
frame.update_idletasks()
canvas_tab.config(scrollregion = frame.bbox("all"))
canvas_tab.bind('', configure)
root.mainloop()