Stewart Midwinter | 1 Mar 15:08 2005
Picon

using list elements in menu construction?

Hi all:

I want to use a list to contain variables in a series of option-menu
toggles.  I've got 15 options to set, so I would like to use a single
for loop to draw the 15 menu items and use a list containing Tkinter
IntVar instances to keep track of the value of these options.  But,
Tkinter doesn't seem to like me using a list member as the variable in
the menu.  Is there a way to do what I want?

Here's a sample app with the offending behaviour:

#test-opts.py
import sys, thread, string, os, time

class rsyncApp:
    def __init__(self, parent):
        '''define rsync defaults; get from settings file if it exists'''
        self.font = ('Helvetica', 10)	#default font
        os.chdir(folder)

    def drawGUI(self, parent):
        '''Create and pack the MenuBar.'''
        menuBar = Pmw.MenuBar(parent,
            hull_relief = 'raised',
            hull_borderwidth = 1)
        menuBar.pack(fill = 'x')
        self.menuBar = menuBar

        # Add some buttons to the MenuBar.
        menuBar.addmenu('File', 'Connect or quit')
(Continue reading)

Jeff Epler | 1 Mar 15:55 2005
Picon

Re: using list elements in menu construction?

I don't see what's wrong with your program, but a simple Tkinter program
not using pmw seems to work just as expected on my system.

It seems like it would be hard for Python/PMW/Tkinter to even know that
a particular option for varible= was computed by a list indexing
operation, as opposed to any other way.

Whatever problem is in your code, I think you may not have identified it
correctly.

Jeff

#------------------------------------------------------------------------
import Tkinter

# Create widgets
t = Tkinter.Tk()
m = Tkinter.Menu(t); t.configure(menu=m)
menu = Tkinter.Menu(m); m.add_cascade(menu=menu, label="Radiobuttons")
opts = [Tkinter.IntVar() for i in range(15)]

# Callback when checkbutton clicked
def print_opts():
    for i in range(15):
        print "Checkbutton %d: %d" % (i, opts[i].get())
    print 

# Populate the checkbutton menu
for i in range(15):
    menu.add_checkbutton(variable=opts[i], label="Checkbutton %d" % i,
(Continue reading)

Stewart Midwinter | 1 Mar 17:07 2005
Picon

Re: using list elements in menu construction?

Jeff:

you're right, there seems to be no problem with using list elements to
construct menus IF you use basic Tkinter menus, and not Pmw menus
(thanks for the example, BTW).   I prefer using Pmw menus, so I'd like
to get this to work, but OTOH it might be easier to use Tkinter menus,
so that the end user doesn't have to have Pmw installed.    BTW, I'm
building a GUI front end for Vivian deSmedt's rsync.py, so my menu
structure will be fairly simple.

cheers,
--

-- 
Stewart Midwinter
stewart <at> midwinter.ca
stewart.midwinter <at> gmail.com
Michael Lange | 1 Mar 20:42 2005
Picon

Re: using list elements in menu construction?

On Tue, 1 Mar 2005 07:08:47 -0700
Stewart Midwinter <stewart.midwinter <at> gmail.com> wrote:

Hi Stewart,

there's a typo in your drawGui() method:

>         for i in range(0,15):
>             print '%s: %i ' % (self.names[i], self.opts[i].get())
>             menuBar.addmenuitem('Options', 'checkbutton', self.names[i],
>                                  ^^^^^^^

I guess you meant 'Edit', at least you have defined an 'Edit' menu and no 'Options' menu before.

Best regards

Michael
Stewart Midwinter | 1 Mar 23:33 2005
Picon

Re: using list elements in menu construction?

Doh!

I guess it's true what they say, that you can't proof-read your own work.!

thanks Michael.

cheers
S

On Tue, 1 Mar 2005 20:42:58 +0100, Michael Lange <klappnase <at> web.de> wrote:

> there's a typo in your drawGui() method:

--

-- 
Stewart Midwinter
stewart <at> midwinter.ca
stewart.midwinter <at> gmail.com
Russell E. Owen | 2 Mar 00:19 2005
Picon

Re: Custom cursor?

In article <20050225115427.04d8ede0.klappnase <at> web.de>,
 Michael Lange <klappnase <at> web.de> wrote:

> You have to use a tuple instead of a string (at least if you want to use a 
> two-colored cursor), like this:
> 
> mycursor = (' <at> /usr/X11R6/include/X11/bitmaps/cntr_ptr', 
> '/usr/X11R6/include/X11/bitmaps/cntr_ptrmsk', 'black', white')
> t.configure(cursor=mycursor)

Thanks everybody for all the help.

In summary:
- unix, MacOS X and Windows each have a different required file format 
(the standard format for cursors on that platform). This makes 
cross-platform cursors in Tkinter a lot of work -- more than I'm ready 
to do right now.

- Unix requirements:
  - specify an xbm format file path plus at least a foreground color
    (a fancier form allows a mask and background color as well);
  - the xbm file must include hotspot info
  - the multiple args must be in a tuple

It is conceivable that if one wrote a C interface to 
Tk_GetCursorFromData, then one form of data might be acceptable to all 
platforms. I'm not ready to try that yet.

Regards,

(Continue reading)

Jared Cohen | 2 Mar 18:39 2005
Picon

Re: Another problem -- deselecting individualentries in Tix HList

Thanks, but that didn't work. I tried the format:  
self.tree.hlist.selection_clear(from_=path)
And I got this error message:

File "/usr/lib/python2.3/lib-tk/Tix.py", line 1015, in selection_clear
    self.tk.call(self._w, 'selection', 'clear', *self._options(cnf, kw))
TclError: Entry "-from" not found

Using the leading underscore resulted in the same error. Any other ideas?
Fredrik Lundh | 2 Mar 20:14 2005

Re: Another problem -- deselecting individual entriesin Tix HList

Jared Cohen wrote:

> According to the documentation for the Tcl version of Tix, it's possible to use selection_clear() 
> to deselect individual entries, as opposed to the entire selection. The documentation says the 
> following:
>
> pathName selection clear ?from? ?to?
>
> When no extra arguments are given, deselects all of the list entrie(s) in this HList widget. When 
> only from is given, only the list entry identified by from is deselected. When both from and to 
> are given, deselects all of the list entrie(s) between between from and to, inclusive, without 
> affecting the selection state of entries outside that range.
>
> However, I can't for the life of me figure out how to get this functionality in Python. You'd 
> think that you could just pass in "from" and "to" as individual arguments, but you'd be wrong --  
> the Python version of selection_clear() has the form:    selection_clear(self, cnf={}, **kw) . It 
> expects a dictionary and/or a keyword list. And I can't figure out the right syntax for that 
> "from-to" thing. Can anyone help please?

might be a bug in the Python binding.  does the following "direct" call
work as expected?

    widget.tk.call(widget, "selection", "clear", fromvalue, tovalue)

</F> 
Jared Cohen | 2 Mar 21:10 2005
Picon

Re: Another problem -- deselecting individualentriesin Tix HList

That works perfectly! Many thanx!! :-)

>might be a bug in the Python binding.  does the following "direct" call
>work as expected?
>
>    widget.tk.call(widget, "selection", "clear", fromvalue, tovalue)
>
Jonathan Stevens | 5 Mar 19:36 2005
Picon

creating a conformation window that does multiple commands

Hello,
I'm new to tkinter, so this might be a stupid question, but please bear with 
me. I have a gui made and when the user goes to file->quit a conformation 
window will pop up asking if they are sure that they want to quit, if "yes" 
then the program will quit. What I can not get it how to get the 
conformation window to be destroyed and the main program will quit with one 
command? Plus can this be done where, for another command instead of qiuting 
the program, i say go to another function but the pop up window does close?

Any advice will be much appreciated and I thank you all for helping me out

Gmane