2个Tkinter帧,1个不在y轴上扩展

时间:2015-11-30 00:36:14

标签: python python-3.x tkinter

我有一个使用Tkinter用Python 3编写的gui应用程序。我有2个包含按钮的框架,我已经设置了按钮和框架以随窗口扩展。

当我展开窗口时,顶部框架在所有方向上展开,但底部框架仅在x轴上展开。

这是设置框架和主窗口的代码:

# Main Window
self.master = master
master.title('Calculator')
master.columnconfigure(0, weight=1)
master.rowconfigure(0, weight=1)

# Top Frame
topfrm = tkinter.Frame(master, bg='#000000')
topfrm.grid(row=0, column=0, sticky='nsew')
for x in range(4):
    topfrm.columnconfigure(x, weight=1)
for y in range(4):
    topfrm.rowconfigure(y, weight=1)

# Bottom Frame
btmfrm = tkinter.Frame(master, bg='#484848')
btmfrm.grid(row=1, column=0, sticky='nsew')
for x in range(4):
    btmfrm.columnconfigure(x, weight=1)
for y in range(5):
    btmfrm.rowconfigure(y, weight=1)

这是生成按钮的代码:

r = 2
c = 0
for t in self.topfrmbtns:
    btn = tkinter.Button(topfrm, text=self.char(t), width=5, fg='#FFFFFF', bg='#000000', bd=0, command=lambda t=t: self.assmeth(t))
    btn.grid(row=r, column=c, sticky='nsew')
    btn.bind("<Enter>", lambda event, e=btn: e.configure(bg="#A9A9A9"))
    btn.bind("<Leave>", lambda event, l=btn: l.configure(bg="#000000"))
    c += 1
    if c > 3:
        c = 0
        r += 1
for b in self.btmfrmbtns:
    btn = tkinter.Button(btmfrm, text=self.char(b), width=5, fg='#FFFFFF', bg='#808080', bd=0, command=lambda b=b: self.assmeth(b))
    btn.grid(row=r, column=c, sticky='nsew')
    btn.bind("<Enter>", lambda event, e=btn: e.configure(bg="#A9A9A9"))
    btn.bind("<Leave>", lambda event, l=btn: l.configure(bg="#808080"))
    c += 1
    if c > 3:
        c = 0
        r += 1

0 个答案:

没有答案