How to place menu on the bottom

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • qxyuestc@yahoo.cn

    How to place menu on the bottom

    #!/usr/bin/env python

    import sys
    import os

    from tkinter import *

    def callback(self):
    #int this snippet, all menu entries use the same callback...
    print("callback ")


    class DemoMenu():
    def __init__(self):
    self.dataTemp = ""
    self.createWidg ets()

    def createWidgets(s elf): # create application GUI
    self.rootWin = Tk()
    self.rootWin.mi nsize(width=800 , height=600)
    self.rootWin.ma xsize(width=800 , height=600)
    self.rootWin.ti tle = ("JoeQ Menu test...")

    self.mainFrame = Frame(self.root Win)

    self.createMenu ()

    def createMenu(self ): # create menu
    menuFrame = Frame(self.root Win)
    menuFrame.pack( side=BOTTOM, fill=X)

    menuBar = Menu(menuFrame, tearoff=1)

    filemenu = Menu(menuBar, tearoff=0)
    filemenu.add_co mmand(label="Op en...", command=callbac k)
    filemenu.add_se parator()
    filemenu.add_co mmand(label="Ex it", command=callbac k)

    menuBar.add_cas cade(label="Fil e", menu=filemenu)

    self.rootWin.co nfig(menu=menuB ar)

    return menuBar

    def start(self):
    self.rootWin.ma inloop()


    if __name__ == '__main__':
    demomenu = DemoMenu()
    demomenu.start( )
    ############### ############### ############### #########
    I want to place the menu on the bottom (menuFrame.pack (side=BOTTOM,
    fill=X)). But it does not work. Why?
  • Fredrik Lundh

    #2
    Re: How to place menu on the bottom

    qxyuestc@yahoo. cn wrote:
    self.rootWin.co nfig(menu=menuB ar)
    I want to place the menu on the bottom (menuFrame.pack (side=BOTTOM,
    fill=X)). But it does not work. Why?
    menubars that are configured via the window menu option are rendered by
    the underlying window system.

    to create a stand-alone menu bar, create a frame and pack or grid it
    where you want it, then add Menubutton widgets to it, and attach your
    pulldown menus to those buttons.

    the following wrapper supports both menu styles; look at the "else"
    clauses in the various "if use_native_menu s" statements for code samples:



    </F>

    Comment

    • qxyuestc@yahoo.cn

      #3
      Re: How to place menu on the bottom

      On Aug 30, 6:04 pm, Fredrik Lundh <fred...@python ware.comwrote:
      qxyue...@yahoo. cn wrote:
              self.rootWin.co nfig(menu=menuB ar)
      I want to place the menu on the bottom (menuFrame.pack (side=BOTTOM,
      fill=X)). But it does not work. Why?
      >
      menubars that are configured via the window menu option are rendered by
      the underlying window system.
      >
      to create a stand-alone menu bar, create a frame and pack or grid it
      where you want it, then add Menubutton widgets to it, and attach your
      pulldown menus to those buttons.
      >
      the following wrapper supports both menu styles; look at the "else"
      clauses in the various "if use_native_menu s" statements for code samples:
      >

      >
      </F>
      step1: I first create a widget "menuFrame" which is belong to the
      rootWin
      ....menuFrame = Frame(self.root Win)
      step2: then I put the widget to the bottom of the rootWin
      ....menuFrame.p ack(side=BOTTOM , fill=X)
      step3: I create a menu belong to the menuFrame.
      ....menuBar = Menu(menuFrame, tearoff=1)
      since menuFrame should be placed to the bottom, so does the menuBar in
      my opinion. What the problem is?

      Comment

      • Fredrik Lundh

        #4
        Re: How to place menu on the bottom

        qxyuestc@yahoo. cn wrote:
        What the problem is?
        the menu is drawn by the window system when you use the "menu" option,
        not by Tkinter.

        </F>

        Comment

        Working...