Re: Tkinter popup menu
On Thu, Aug 28, 2008 at 3:50 AM, Carl <[EMAIL PROTECTED]> wrote: > "Chuckk Hubbard" <[EMAIL PROTECTED]> writes: > >> Right-click popup menu. None of the options that come from the >> cascades can be selected with the mouse. If you select a submenu with >> the mouse and then use the arrow keys and enter key to select an >> option, it works, but the menu remains on the canvas. If you click >> the option with the mouse, the menu disappears but the function >> doesn't get called. >> Can someone tell me why? >> >> -Chuckk >> >> -- >> http://www.badmuthahubbard.com > > Try creating the "main" popup menu before the sub-menus, and when > instantiating the sub-menus, pass the main menu as the "master" > instead of "self.myparent": Thanks Carl, that indeed did it. -Chuckk > > Hope that helps. > Carl. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://www.badmuthahubbard.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter popup menu
"Chuckk Hubbard" <[EMAIL PROTECTED]> writes: > Right-click popup menu. None of the options that come from the > cascades can be selected with the mouse. If you select a submenu with > the mouse and then use the arrow keys and enter key to select an > option, it works, but the menu remains on the canvas. If you click > the option with the mouse, the menu disappears but the function > doesn't get called. > Can someone tell me why? > > -Chuckk > > -- > http://www.badmuthahubbard.com Try creating the "main" popup menu before the sub-menus, and when instantiating the sub-menus, pass the main menu as the "master" instead of "self.myparent": ...snip code - self.canvas.bind("",self.popup) self.menupopup = tk.Menu(self.myparent, tearoff=0) self.menupopup1 = tk.Menu(self.menupopup, tearoff=0) self.menupopup1.add_command(label="Test1", command=self.selected) self.menupopup1.add_command(label="Test2", command=self.selected) self.menupopup1.add_command(label="Test3", command=self.selected) self.menupopup2 = tk.Menu(self.menupopup, tearoff=0) self.menupopup2.add_command(label="Test1", command=self.selected) self.menupopup2.add_command(label="Test2", command=self.selected) self.menupopup2.add_command(label="Test3", command=self.selected) #self.menupopup = tk.Menu(self.myparent, tearoff=0) self.menupopup.add_cascade(label="Test1", menu=self.menupopup1) self.menupopup.add_cascade(label="Test2", menu=self.menupopup2) ...end code changes -- Hope that helps. Carl. -- http://mail.python.org/mailman/listinfo/python-list
Tkinter popup menu
Right-click popup menu. None of the options that come from the cascades can be selected with the mouse. If you select a submenu with the mouse and then use the arrow keys and enter key to select an option, it works, but the menu remains on the canvas. If you click the option with the mouse, the menu disappears but the function doesn't get called. Can someone tell me why? -Chuckk -- http://www.badmuthahubbard.com #!/usr/bin/python2.4 import Tkinter as tk class App: def __init__(self, parent): self.myparent = parent self.myparent.rowconfigure(0, weight=1) self.myparent.columnconfigure(0, weight=1) self.canvas = tk.Canvas(self.myparent) self.canvas.grid(row=0, column=0, sticky='nesw') self.canvas.bind("",self.popup) self.menupopup1 = tk.Menu(self.myparent, tearoff=0) self.menupopup1.add_command(label="Test1", command=self.selected) self.menupopup1.add_command(label="Test2", command=self.selected) self.menupopup1.add_command(label="Test3", command=self.selected) self.menupopup2 = tk.Menu(self.myparent, tearoff=0) self.menupopup2.add_command(label="Test1", command=self.selected) self.menupopup2.add_command(label="Test2", command=self.selected) self.menupopup2.add_command(label="Test3", command=self.selected) self.menupopup = tk.Menu(self.myparent, tearoff=0) self.menupopup.add_cascade(label="Test1", menu=self.menupopup1) self.menupopup.add_cascade(label="Test2", menu=self.menupopup2) def selected(self): print "Selected" def popup(self,event): self.menupopup.post(event.x_root,event.y_root) root = tk.Tk() app = App(root) root.mainloop() -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter popup
Eric Brunel wrote: > On Tue, 27 Mar 2007 12:05:07 +0200, Gigs_ <[EMAIL PROTECTED]> wrote: > >> Hi all >> >> I cant figure out how to disable resizing of my popup window? > > myPopupWindow.wm_resizable(0, 0) > > It may or may not make resize controls disappear depending on your > platform and/or window manager. But the resizing will be impossible in > any case. > >> How to put this popup window to show in the middle of my text editor? >> It is writen with Toplevel. > > A bit trickier. For example (untested): > > myPopupWindow.after_idle(centerPopupWindow) > > with: > > def centerPopupWindow(): > x, y = editorWindow.winfo_rootx(), editorWindow.winfo_rooty() > w, h = editorWindow.winfo_width(), editorWindow.winfo_height() > ww, hh = myPopupWindow.winfo_width(), myPopupWindow.winfo_height() > myPopupWindow.geometry('%sx%s+%s+%s', ww, hh, x + w/2 - ww/2, y + h/2 > - hh/2) > > The after_idle trick is needed since the dimensions for the popup window > will only be known when the window is actually displayed. In theory, > myPopupWindow.update_idletasks() should update the display so that the > window dimensions are known, but there are cases where it doesn't work. > So the after_idle trick is surer. > > HTH > --python -c "print ''.join([chr(154 - ord(c)) for c in > 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" thanks for both replay, they are very helpful. specially this one, it will took some times for me to figure this. i was completely forgot that this can be done like that thx -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter popup
On Tue, 27 Mar 2007 12:05:07 +0200, Gigs_ <[EMAIL PROTECTED]> wrote: > Hi all > > I cant figure out how to disable resizing of my popup window? myPopupWindow.wm_resizable(0, 0) It may or may not make resize controls disappear depending on your platform and/or window manager. But the resizing will be impossible in any case. > How to put this popup window to show in the middle of my text editor? > It is writen with Toplevel. A bit trickier. For example (untested): myPopupWindow.after_idle(centerPopupWindow) with: def centerPopupWindow(): x, y = editorWindow.winfo_rootx(), editorWindow.winfo_rooty() w, h = editorWindow.winfo_width(), editorWindow.winfo_height() ww, hh = myPopupWindow.winfo_width(), myPopupWindow.winfo_height() myPopupWindow.geometry('%sx%s+%s+%s', ww, hh, x + w/2 - ww/2, y + h/2 - hh/2) The after_idle trick is needed since the dimensions for the popup window will only be known when the window is actually displayed. In theory, myPopupWindow.update_idletasks() should update the display so that the window dimensions are known, but there are cases where it doesn't work. So the after_idle trick is surer. HTH -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" -- http://mail.python.org/mailman/listinfo/python-list
tkinter popup
Hi all I cant figure out how to disable resizing of my popup window? How to put this popup window to show in the middle of my text editor? It is writen with Toplevel. thx -- http://mail.python.org/mailman/listinfo/python-list