python界面菜单中文_Tkinter GUI中的菜单、按钮等栏

用pack()做的。我确信它也可以用grid()完成,但我对它不太熟悉。在from Tkinter import *

def clickTest():

print "Click!"

class App(Tk):

def __init__(self):

Tk.__init__(self)

menuBar = MenuBar(self)

buttonBar = ButtonBar(self)

self.config(menu=menuBar)

buttonBar.pack()

class MenuBar(Menu):

def __init__(self, parent):

Menu.__init__(self, parent)

fileMenu = Menu(self, tearoff=False)

self.add_cascade(label="File", menu=fileMenu)

fileMenu.add_command(label="Exit", command=clickTest)

class ButtonBar(Frame):

def __init__(self, parent):

Frame.__init__(self, parent)

firstButton = Button(self, text="1st Button", command=clickTest).pack()

secondButton = Button(self, text="2nd Button", command=clickTest).pack()

if __name__ == "__main__":

app = App()

app.mainloop()

另一件事是,您应该将buttons parent设置为Frame,如下所示:

^{pr2}$

这里我用parent改了self。self是框架本身,而不是整个顶层窗口。使用pack()函数,我将按钮打包到其父级中,在本例中是框架。在

然后用buttonBar.pack()将按钮栏打包到顶层窗口中。你也可以在这里和框架中使用网格。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值