4 Replies - 207 Views - Last Post: 20 February 2015 - 03:58 PM Rate Topic: -----

#1 grafs50  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 23-March 14

Problems with Menubutton in tkinter

Posted 20 February 2015 - 11:23 AM

I'm just trying to get a Menubutton to appear in the upper-right corner of the frame. Instead, the Menubutton is appearing in the center of the screen. After sifting through all the documentation I could find on Menubutton, though, I can't figure out why its doing it.

Here's the code:

import tkinter
from tkinter import *

"""

    Documentation:
    Goal: Create a simple notepad program with the complete functionality of the
    Windows Notepad programe

    -Create subclasses Frame, Menu, etc.
    -Piece all of these classes together

"""

class TopFrame(tkinter.Frame):

    def __init__(self, master):

        tkinter.Frame.__init__(self, master)
        self.grid(padx=400, pady=150)

class MenuButton(tkinter.Menubutton):

    def __init__(self, master,):

        tkinter.Menubutton.__init__(self, master, relief=RAISED, text="test")
        self.grid(column=0, row=0, padx=5, pady=5)

        

topframe = TopFrame(None)
menubutton = MenuButton(topframe)        





Is This A Good Question/Topic? 0
  • +

Replies To: Problems with Menubutton in tkinter

#2 andrewsw  Icon User is online

  • I'm not here to twist your niblets
  • member icon

Reputation: 4033
  • View blog
  • Posts: 14,472
  • Joined: 12-December 12

Re: Problems with Menubutton in tkinter

Posted 20 February 2015 - 11:53 AM

I don't know much about tkinter but I believe you should associate the button with a menu:

Quote

To actually create a menubar for a window, we first create a menu widget, and then use the window's "menu" configuration option to attach the menu widget to the window. As noted, the menu widget must be a child of the toplevel window.

win = Toplevel(root)
menubar = Menu(win)
win['menu'] = menubar

TkDocs
Was This Post Helpful? 0
  • +
  • -

#3 grafs50  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 23-March 14

Re: Problems with Menubutton in tkinter

Posted 20 February 2015 - 12:03 PM

Thought it was the other way around. Thanks I'll try that!

This post has been edited by andrewsw: 20 February 2015 - 12:05 PM
Reason for edit:: Removed previous quote, just press REPLY

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • I'm not here to twist your niblets
  • member icon

Reputation: 4033
  • View blog
  • Posts: 14,472
  • Joined: 12-December 12

Re: Problems with Menubutton in tkinter

Posted 20 February 2015 - 12:05 PM

Ok.

Note that you don't have to quote the entire previous post, there is a Reply button further down the page.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • I'm not here to twist your niblets
  • member icon

Reputation: 4033
  • View blog
  • Posts: 14,472
  • Joined: 12-December 12

Re: Problems with Menubutton in tkinter

Posted 20 February 2015 - 03:58 PM

This looks to be a good tutorial, zetcode, that also takes a class-based approach.

Spoiler

Attached Image
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1