473,785 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tkinter menus

class MenuDemo(Frame) :
def __init__(self, parent=None):
Frame.__init__( self, parent)
self.pack(expan d=YES, fill=BOTH)
self.createWidg ets()

def createWidgets(s elf):
self.makeMenuBa r()
self.makeToolBa r()
L = Label(self, text='Menu and Toolbar demo')
L.config(relief =SUNKEN, width=40, height=10, bg='white')
L.pack(expand=Y ES, fill=BOTH)

def makeMenuBar(sel f):
self.menubar = Menu(self.maste r) #here
self.master.con fig(menu=self.m enubar) #here
self.fileMenu()
self.editMenu()
self.imageMenu( )

why i need to use self.master?
why i cant just use self?

thx
Mar 1 '07 #1
4 1887
Gigs_ wrote:
class MenuDemo(Frame) :
def __init__(self, parent=None):
Frame.__init__( self, parent)
self.pack(expan d=YES, fill=BOTH)
self.createWidg ets()

def createWidgets(s elf):
self.makeMenuBa r()
self.makeToolBa r()
L = Label(self, text='Menu and Toolbar demo')
L.config(relief =SUNKEN, width=40, height=10, bg='white')
L.pack(expand=Y ES, fill=BOTH)

def makeMenuBar(sel f):
self.menubar = Menu(self.maste r) #here
self.master.con fig(menu=self.m enubar) #here
self.fileMenu()
self.editMenu()
self.imageMenu( )

why i need to use self.master?
why i cant just use self?

thx
master is a reference to a Tk() or Toplevel(). Frames do not contain
menus, but the windows that contain them do.

James
Mar 1 '07 #2
On Thu, 01 Mar 2007 22:35:40 +0100, James Stroud <js*****@mbi.uc la.edu
wrote:
Gigs_ wrote:
>class MenuDemo(Frame) :
def __init__(self, parent=None):
Frame.__init__( self, parent)
self.pack(expan d=YES, fill=BOTH)
self.createWidg ets()
def createWidgets(s elf):
self.makeMenuBa r()
self.makeToolBa r()
L = Label(self, text='Menu and Toolbar demo')
L.config(relief =SUNKEN, width=40, height=10, bg='white')
L.pack(expand=Y ES, fill=BOTH)
def makeMenuBar(sel f):
self.menubar = Menu(self.maste r) #here
self.master.con fig(menu=self.m enubar) #here
self.fileMenu()
self.editMenu()
self.imageMenu( )
why i need to use self.master?
why i cant just use self?
thx

master is a reference to a Tk() or Toplevel(). Frames do not contain
menus, but the windows that contain them do.
This is the main reason why I always rant about examples of Tkinter
programming creating windows by sub-classing Frame: frames are not
windows. If you want to create a window, sub-class Toplevel (or Tk), not
Frame. A frame is a general-purpose container. It can be sub-classed to
create new "mega-widgets" that can be used in any context. This is
obviously not the case in the code above, as the parent passed to any
instance of MenuDemo *must* be a Toplevel or Tk. So just write:

class MenuDemo(Toplev el):
def __init__(self):
Toplevel.__init __(self)
...
def makeMenuBar(sel f):
self.menubar = Menu(self)
self.config(men u=self.menubar)
...

and your life will be easier ;-)

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz 5(17l8(%,5.Z*(9 3-965$l7+-'])"
Mar 2 '07 #3
>master is a reference to a Tk() or Toplevel(). Frames do not contain
>menus, but the windows that contain them do.

This is the main reason why I always rant about examples of Tkinter
programming creating windows by sub-classing Frame: frames are not
windows. If you want to create a window, sub-class Toplevel (or Tk), not
Frame. A frame is a general-purpose container. It can be sub-classed to
create new "mega-widgets" that can be used in any context. This is
obviously not the case in the code above, as the parent passed to any
instance of MenuDemo *must* be a Toplevel or Tk. So just write:

class MenuDemo(Toplev el):
def __init__(self):
Toplevel.__init __(self)
...
def makeMenuBar(sel f):
self.menubar = Menu(self)
self.config(men u=self.menubar)
...

and your life will be easier ;-)

HTH
--python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz 5(17l8(%,5.Z*(9 3-965$l7+-'])"
btw im tkinter newbie so this question could be stupid

is it alright to use Menu instead Toplevel or Tk
like this?

from Tkinter import *
from tkMessageBox import *

class MenuDemo(Menu):
def __init__(self, master=None):
Menu.__init__(s elf, master)
self.createWidg ets()
self.master.tit le('Toolbars and Mennus')
self.master.ico nname('tkpython ')

def createWidgets(s elf):
self.makeMenuBa r()
self.makeToolBa r()
L = Label(self.mast er, text='Menu and Toolbar demo')
L.config(relief =SUNKEN, width=40, height=10, bg='white')
L.pack(expand=Y ES, fill=BOTH)
Mar 2 '07 #4
On Fri, 02 Mar 2007 13:41:12 +0100, Gigs_ <gi**@hi.t-com.hrwrote:
is it alright to use Menu instead Toplevel or Tk
like this?

from Tkinter import *
from tkMessageBox import *

class MenuDemo(Menu):
def __init__(self, master=None):
Menu.__init__(s elf, master)
self.createWidg ets()
self.master.tit le('Toolbars and Mennus')
self.master.ico nname('tkpython ')

def createWidgets(s elf):
self.makeMenuBa r()
self.makeToolBa r()
L = Label(self.mast er, text='Menu and Toolbar demo')
L.config(relief =SUNKEN, width=40, height=10, bg='white')
L.pack(expand=Y ES, fill=BOTH)
Feels weird to me. Creating widgets in a window from what is supposed to
its its menu is quite unexpected. I would definitely create a sub-class of
Toplevel or Tk and create the menu in it.

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz 5(17l8(%,5.Z*(9 3-965$l7+-'])"
Mar 2 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5986
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles filling the remainder of the window. Mind you, this is a contrived test application to help me understand Tkinter and Python, not an actual application yet. I've trivially subclassed Tkinter.Canvas into ColorCanvas, added a bunch of ColorCanvases...
2
2103
by: James Ash | last post by:
I'm writing a very simple and small Ptyhon/Tkinter application and I'm having trouble getting the menus to appear correctly. Rather than a name appearing on the menu bar, I see "()" instead. Clicking on these "()" does nothing (other than changing the appearance of them to indicated they've been pressed). I'm using Python 2.2.3 on Win2K, using a release downloaded from one of the Cygwin mirrors. This is most likely a simple mistake...
2
4637
by: Stewart Midwinter | last post by:
I would like to link the contents of three OptionMenu lists. When I select an item from the first list (call it continents), the contents of the 2nd list (call it countries) would update. And in turn the contents of the 3rd list (call it states would be updated by a change in the 2nd list. If anyone can share a recipe or some ideas, I'd be grateful! Here's some sample code that displays three OptionMenus, but doesn't update the list...
0
1099
by: Dan Greenblatt | last post by:
I know this can be done for context menus with the 'post' command.... What I'm trying to do, though, is programmatically post non-contextual menus (i.e. menus that exist on a horizontal menu bar at the top of my application window) in the correct place. So if I have five different menus (i guess these are menubuttons?) placed horizontally on my menu bar, and the third one is 'Actions', what is the best way to determine the x and y...
6
4492
by: Bob Greschke | last post by:
Root.option_add("*?????*font", "Helvetica 12 bold") Want to get rid of the "font =": Widget.add_cascade(label = "File", menu = Fi, font = "Helvetica 12 bold") Does anyone know what ????? should be to control the font of the cascade menus (the labels on the menu bar)? "*Menu*font" handles the part that drops down, but I can't come up with the menu bar labels part. Thanks!
1
1968
by: MichaelW | last post by:
I've been Python (2.3.4) plus Tkinter happily under MacOX 10.3, having compiled them from scatch. (Tkinter is based on tcl/tk 8.4.1, which were compiled from source via Fink). I then moved my laptop over the 10.4, and things are now breaking. Using the Python shipped with 10.4 (which has Tkinter based on tcl/tk 8.4.7) the window in a particular application looks completely different (more Apple-like) and the buttons no longer work...
0
2360
by: Stewart Midwinter | last post by:
I have a Tkinter app running on cygwin. It includes a Test menu item that does nothing more than fetch a directory listing and display it in a Toplevel window (I'd use a tkMessageBox showinfo widget, but for some reason the text is invisible on cygwin). After I close the Toplevel widget, all of the menus in my app behave as though they have no contents to them, i..e I can press on the File menu button, and see it depress, but the Exit...
2
2844
by: ishtar2020 | last post by:
Hi everybody I'd appreciate some help on creating a tear off menu with TkInter. I've been reading some documentation but still no luck. Please don't get confused: when I mean "tear off" menu I don't mean a drop-down or a pop-up menu, but those options which yield to another batch of sub-options when scrolled over, (as for example, the File->New option from internet explorer).
2
5203
by: Andrew Trevorrow | last post by:
Our app uses embedded Python to allow users to run arbitrary scripts. Scripts that import Tkinter run fine on Windows, but on Mac OS X there is a serious problem. After a script does "root = Tk()" our app's menus are permanently changed in the following way: - The top item in the application menu changes to "About Tcl & Tk...". - The Quit item is disabled. - The File and Edit menus are completely replaced. - All further menus (except...
44
5010
by: bg_ie | last post by:
Hi, I'm in the process of writing some code and noticed a strange problem while doing so. I'm working with PythonWin 210 built for Python 2.5. I noticed the problem for the last py file processed by this script, where the concerned tmp file is only actually written to when PythonWin is closed. In other words, after I run this script, one of the generated tmp files has a size of 0kB. I then close PythonWin and it is then written to.
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.