Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #105506 > unrolled thread

Key Binding Problem

Started byWildman <best_lay@yahoo.com>
First post2016-03-22 21:46 -0500
Last post2016-03-22 23:30 -0500
Articles 15 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Key Binding Problem Wildman <best_lay@yahoo.com> - 2016-03-22 21:46 -0500
    Re: Key Binding Problem MRAB <python@mrabarnett.plus.com> - 2016-03-23 03:02 +0000
      Re: Key Binding Problem Wildman <best_lay@yahoo.com> - 2016-03-22 23:28 -0500
        Re: Key Binding Problem Terry Reedy <tjreedy@udel.edu> - 2016-03-23 02:47 -0400
          Re: Key Binding Problem Wildman <best_lay@yahoo.com> - 2016-03-23 10:40 -0500
          Re: Key Binding Problem Wildman <best_lay@yahoo.com> - 2016-03-23 10:58 -0500
            Re: Key Binding Problem Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-03-23 20:34 -0400
              Re: Key Binding Problem Wildman <best_lay@yahoo.com> - 2016-03-23 21:17 -0500
                Re: Key Binding Problem Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-03-24 08:06 -0400
                  Re: Key Binding Problem Wildman <best_lay@yahoo.com> - 2016-03-24 11:19 -0500
                    Re: Key Binding Problem Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-03-24 21:43 -0400
                      Re: Key Binding Problem Wildman <best_lay@yahoo.com> - 2016-03-24 23:37 -0500
                        Re: Key Binding Problem Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-03-25 12:50 -0400
    Re: Key Binding Problem Terry Reedy <tjreedy@udel.edu> - 2016-03-22 23:52 -0400
      Re: Key Binding Problem Wildman <best_lay@yahoo.com> - 2016-03-22 23:30 -0500

#105506 — Key Binding Problem

FromWildman <best_lay@yahoo.com>
Date2016-03-22 21:46 -0500
SubjectKey Binding Problem
Message-ID<o6ydncSeoNfrnm_LnZ2dnUU7-IfNnZ2d@giganews.com>
Platform: Linux
Python: v.2.7.9
Tkinter: v.8.6.2

My program has some buttons for file operations, load_image,
save_image, and quit.  I would like to bind a key that will
execute the procedures for each of the buttons.  The binding
for the quit button was easy...

root.bind("<q>", quit)
root.bind("<Q>", quit)

That works but it not executing a quit button procedure.
It is merely executing an internal command.  My problem is
calling an actual button procedure.  Over the last several
hours I have tried many different syntax arrangements and
I keep getting "object not defined" errors.  I also tried
placing the bind statements into other places in the code.
I have run out of ideas.

Below is a basic skeleton of my code.  Any help appreciated.

#!/usr/bin/env python

try:
    import Tkinter as tk
    from Tkinter import Tk
except ImportError:
    import tkinter as tk
    from tkinter import Tk
import tkFileDialog, tkMessageBox
import Image, ImageTk
import base64, io, os, subprocess

class cv():

    # global variables

class Window(tk.Frame):

    def __init__(self, master = None):
        tk.Frame.__init__(self,master)
        self.master = master
        self.init_window()

    def init_window(self):
        self.master.title("My Program")
        self.pack(fill=tk.BOTH, expand=1)
        self.quitButton = tk.Button(self,
                                    text="Quit",
                                    underline=0,
                                    width=10,
                                    command=self.quit)
        self.quitButton.place(x=224, y=422)

        self.loadButton = tk.Button(self,
                                    text="Load Image",
                                    underline=0,
                                    width = 10,
                                    command=self.load_image)
        self.loadButton.place(x=138, y=46)

        # create the rest of the widgets

    def load_image(self):
        # load image file

    def save_image(self):
        # save the image

    def other procedure definitions

root = Tk()
root.bind("<q>", quit)  # these two work
root.bind("<Q>", quit)
root.bind("<l>", load_image)  # these do not work
root.bind("<L>", load_image)  # object not defined errors
root.bind("<s>", save_image)
root.bind("<S>", save_image)
root.minsize(width=554, height=462)
root.maxsize(width=554, height=462)
app = Window(root)
root.mainloop()

My question is how do I coax bind into executing the
button procedures?  Or is there a way to generate the
button click event from the binding?

-- 
<Wildman> GNU/Linux user #557453
"Be at war with your vices, at peace with your neighbors,
and let every new year find you a better man."
  -Benjamin Franklin

[toc] | [next] | [standalone]


#105507

FromMRAB <python@mrabarnett.plus.com>
Date2016-03-23 03:02 +0000
Message-ID<mailman.27.1458702187.2244.python-list@python.org>
In reply to#105506
On 2016-03-23 02:46, Wildman via Python-list wrote:
> Platform: Linux
> Python: v.2.7.9
> Tkinter: v.8.6.2
>
> My program has some buttons for file operations, load_image,
> save_image, and quit.  I would like to bind a key that will
> execute the procedures for each of the buttons.  The binding
> for the quit button was easy...
>
> root.bind("<q>", quit)
> root.bind("<Q>", quit)
>
> That works but it not executing a quit button procedure.
> It is merely executing an internal command.  My problem is
> calling an actual button procedure.  Over the last several
> hours I have tried many different syntax arrangements and
> I keep getting "object not defined" errors.  I also tried
> placing the bind statements into other places in the code.
> I have run out of ideas.
>
> Below is a basic skeleton of my code.  Any help appreciated.
>
> #!/usr/bin/env python
>
> try:
>      import Tkinter as tk
>      from Tkinter import Tk
> except ImportError:
>      import tkinter as tk
>      from tkinter import Tk
> import tkFileDialog, tkMessageBox
> import Image, ImageTk
> import base64, io, os, subprocess
>
> class cv():
>
>      # global variables
>
> class Window(tk.Frame):
>
>      def __init__(self, master = None):
>          tk.Frame.__init__(self,master)
>          self.master = master
>          self.init_window()
>
>      def init_window(self):
>          self.master.title("My Program")
>          self.pack(fill=tk.BOTH, expand=1)
>          self.quitButton = tk.Button(self,
>                                      text="Quit",
>                                      underline=0,
>                                      width=10,
>                                      command=self.quit)
>          self.quitButton.place(x=224, y=422)
>
>          self.loadButton = tk.Button(self,
>                                      text="Load Image",
>                                      underline=0,
>                                      width = 10,
>                                      command=self.load_image)
>          self.loadButton.place(x=138, y=46)
>
>          # create the rest of the widgets
>
>      def load_image(self):
>          # load image file
>
>      def save_image(self):
>          # save the image
>
>      def other procedure definitions
>
> root = Tk()
> root.bind("<q>", quit)  # these two work
> root.bind("<Q>", quit)
> root.bind("<l>", load_image)  # these do not work
> root.bind("<L>", load_image)  # object not defined errors
> root.bind("<s>", save_image)
> root.bind("<S>", save_image)
> root.minsize(width=554, height=462)
> root.maxsize(width=554, height=462)
> app = Window(root)
> root.mainloop()
>
> My question is how do I coax bind into executing the
> button procedures?  Or is there a way to generate the
> button click event from the binding?
>
It won't let you bind to a function called "load_image" because there 
isn't a function called "load_image"!

The "Window" class, however, does have a method with that name.

Try binding the keys in Window.__init__ or Window.init_window:

     def init_window(self):
         ...
         root.bind("<l>", self.load_image)

[toc] | [prev] | [next] | [standalone]


#105510

FromWildman <best_lay@yahoo.com>
Date2016-03-22 23:28 -0500
Message-ID<L6KdnXoY773thm_LnZ2dnUU7-QOdnZ2d@giganews.com>
In reply to#105507
On Wed, 23 Mar 2016 03:02:51 +0000, MRAB wrote:

> On 2016-03-23 02:46, Wildman via Python-list wrote:
>> My question is how do I coax bind into executing the
>> button procedures?  Or is there a way to generate the
>> button click event from the binding?
>>
> It won't let you bind to a function called "load_image" because there 
> isn't a function called "load_image"!
> 
> The "Window" class, however, does have a method with that name.
> 
> Try binding the keys in Window.__init__ or Window.init_window:
> 
>      def init_window(self):
>          ...
>          root.bind("<l>", self.load_image)

Here is what I tried:

class Window(tk.Frame):

    def __init__(self, master = None):
        tk.Frame.__init__(self,master)
        self.master = master
        root.bind("l", self.load_image)

I get this error and it doesn't make any sense to me:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1535, in __call__
    return self.func(*args)
TypeError: load_image() takes exactly 1 argument (2 given)

-- 
<Wildman> GNU/Linux user #557453
The cow died so I don't need your bull!

[toc] | [prev] | [next] | [standalone]


#105517

FromTerry Reedy <tjreedy@udel.edu>
Date2016-03-23 02:47 -0400
Message-ID<mailman.31.1458715678.2244.python-list@python.org>
In reply to#105510
On 3/23/2016 12:28 AM, Wildman via Python-list wrote:
> On Wed, 23 Mar 2016 03:02:51 +0000, MRAB wrote:
>
>> On 2016-03-23 02:46, Wildman via Python-list wrote:
>>> My question is how do I coax bind into executing the
>>> button procedures?  Or is there a way to generate the
>>> button click event from the binding?
>>>
>> It won't let you bind to a function called "load_image" because there
>> isn't a function called "load_image"!
>>
>> The "Window" class, however, does have a method with that name.
>>
>> Try binding the keys in Window.__init__ or Window.init_window:
>>
>>       def init_window(self):
>>           ...
>>           root.bind("<l>", self.load_image)
>
> Here is what I tried:
>
> class Window(tk.Frame):
>
>      def __init__(self, master = None):
>          tk.Frame.__init__(self,master)
>          self.master = master
>          root.bind("l", self.load_image)
>
> I get this error and it doesn't make any sense to me:
>
> Exception in Tkinter callback
> Traceback (most recent call last):
>    File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1535, in __call__
>      return self.func(*args)
> TypeError: load_image() takes exactly 1 argument (2 given)

Event handlers must have one parameter (other than 'self' for methods), 
the event, as that is what they will be passed.  You defined load_image 
like this.

     def load_image(self):
         # load image file

It should be this

     def load_image(self, event):
         # load image file

You are free to ignore the event object and some people then name the 
parameter '_' (or dummy) to signify that it will be ignored.

     def load_image(self, _):
         # load image file

You must pass the bound method, as you did, and not the function itself 
(which has two parameters).

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#105557

FromWildman <best_lay@yahoo.com>
Date2016-03-23 10:40 -0500
Message-ID<GZ-dnUhlpat-JW_LnZ2dnUU7-S-dnZ2d@giganews.com>
In reply to#105517
On Wed, 23 Mar 2016 02:47:47 -0400, Terry Reedy wrote:

> On 3/23/2016 12:28 AM, Wildman via Python-list wrote:
>> On Wed, 23 Mar 2016 03:02:51 +0000, MRAB wrote:
>>
>>> On 2016-03-23 02:46, Wildman via Python-list wrote:
>>>> My question is how do I coax bind into executing the
>>>> button procedures?  Or is there a way to generate the
>>>> button click event from the binding?
>>>>
>>> It won't let you bind to a function called "load_image" because there
>>> isn't a function called "load_image"!
>>>
>>> The "Window" class, however, does have a method with that name.
>>>
>>> Try binding the keys in Window.__init__ or Window.init_window:
>>>
>>>       def init_window(self):
>>>           ...
>>>           root.bind("<l>", self.load_image)
>>
>> Here is what I tried:
>>
>> class Window(tk.Frame):
>>
>>      def __init__(self, master = None):
>>          tk.Frame.__init__(self,master)
>>          self.master = master
>>          root.bind("l", self.load_image)
>>
>> I get this error and it doesn't make any sense to me:
>>
>> Exception in Tkinter callback
>> Traceback (most recent call last):
>>    File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1535, in __call__
>>      return self.func(*args)
>> TypeError: load_image() takes exactly 1 argument (2 given)
> 
> Event handlers must have one parameter (other than 'self' for methods), 
> the event, as that is what they will be passed.  You defined load_image 
> like this.
> 
>      def load_image(self):
>          # load image file
> 
> It should be this
> 
>      def load_image(self, event):
>          # load image file
> 
> You are free to ignore the event object and some people then name the 
> parameter '_' (or dummy) to signify that it will be ignored.
> 
>      def load_image(self, _):
>          # load image file
> 
> You must pass the bound method, as you did, and not the function itself 
> (which has two parameters).

Thank you very much.  I have seen sample code that used
'event' in the definition but without any explanation
as to why and without actually using it.  Since my code
seemed to run OK without it, at least until now, I didn't
give it much thought.  My mistake.

I am new to python so understanding comes a little slower
for me.  And I am not a professional programmer.  I enjoy
it as a hobby so my experience is more limited where the
advanced topics are concerned.  Thanks to the knowledgeable
people here I am gaining insight as I go.  Thanks again!

-- 
<Wildman> GNU/Linux user #557453
May the Source be with you.

[toc] | [prev] | [next] | [standalone]


#105558

FromWildman <best_lay@yahoo.com>
Date2016-03-23 10:58 -0500
Message-ID<GZ-dnUtlpauMIG_LnZ2dnUU7-S-dnZ2d@giganews.com>
In reply to#105517
On Wed, 23 Mar 2016 02:47:47 -0400, Terry Reedy wrote:

>      def load_image(self, _):
>          # load image file
> 
> You must pass the bound method, as you did, and not the function itself 
> (which has two parameters).

I meant to ask a followup question in my previous post but
it slipped my mind.

What is the best thing to do...
Define all procedures this way, (self. event)?
Define all event handlers this way?
Define only the event handlers that will be called from
elsewhere in the code, as in this case?

-- 
<Wildman> GNU/Linux user #557453
More gun laws will reduce gun violence just
like Obamacare reduced insurance rates.

[toc] | [prev] | [next] | [standalone]


#105578

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2016-03-23 20:34 -0400
Message-ID<mailman.74.1458780091.2244.python-list@python.org>
In reply to#105558
On Wed, 23 Mar 2016 10:58:09 -0500, Wildman via Python-list
<python-list@python.org> declaimed the following:

>On Wed, 23 Mar 2016 02:47:47 -0400, Terry Reedy wrote:
>
>>      def load_image(self, _):
>>          # load image file
>> 
>> You must pass the bound method, as you did, and not the function itself 
>> (which has two parameters).
>
>I meant to ask a followup question in my previous post but
>it slipped my mind.
>
>What is the best thing to do...
>Define all procedures this way, (self. event)?

	Not "." but "," -- separate arguments

	Anything that is a method in a class object will tend to receive the
object itself as the first argument (commonly called "self" in Python, "me"
in Visual BASIC, "this" in C++). Tk callback functions (I think you were
using Tkinter) likely pass the event data (that is, what triggered the
callback -- a key-in callback passes information about the key that was
pressed).

>Define all event handlers this way?

	If they are methods of a Tk class, then likely they need this format...
But for classes you create yourself, it depends on how you intend to invoke
them.

>Define only the event handlers that will be called from
>elsewhere in the code, as in this case?

	Uhm... If an event handler is never invoked, why write it?
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#105582

FromWildman <best_lay@yahoo.com>
Date2016-03-23 21:17 -0500
Message-ID<06adnbnMouHI027LnZ2dnUU7-XednZ2d@giganews.com>
In reply to#105578
On Wed, 23 Mar 2016 20:34:08 -0400, Dennis Lee Bieber wrote:

> On Wed, 23 Mar 2016 10:58:09 -0500, Wildman via Python-list
> <python-list@python.org> declaimed the following:
> 
>>On Wed, 23 Mar 2016 02:47:47 -0400, Terry Reedy wrote:
>>
>>>      def load_image(self, _):
>>>          # load image file
>>> 
>>> You must pass the bound method, as you did, and not the function itself 
>>> (which has two parameters).
>>
>>I meant to ask a followup question in my previous post but
>>it slipped my mind.
>>
>>What is the best thing to do...
>>Define all procedures this way, (self. event)?
> 
> 	Not "." but "," -- separate arguments

That was a typo.  My fingers have dyslexia.

> 	Anything that is a method in a class object will tend to receive the
> object itself as the first argument (commonly called "self" in Python, "me"
> in Visual BASIC, "this" in C++). Tk callback functions (I think you were
> using Tkinter) likely pass the event data (that is, what triggered the
> callback -- a key-in callback passes information about the key that was
> pressed).
> 
>>Define all event handlers this way?
> 
> 	If they are methods of a Tk class, then likely they need this format...
> But for classes you create yourself, it depends on how you intend to invoke
> them.

Thanks for the info.

>>Define only the event handlers that will be called from
>>elsewhere in the code, as in this case?
> 
> 	Uhm... If an event handler is never invoked, why write it?

I was referring to procedures called by a button click as
opposed to a procedure calledd from elsewhere in the code.
I guess there is no difference.  I assume that is what you
meant.

-- 
<Wildman> GNU/Linux user #557453
The cow died so I don't need your bull!

[toc] | [prev] | [next] | [standalone]


#105603

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2016-03-24 08:06 -0400
Message-ID<mailman.90.1458821171.2244.python-list@python.org>
In reply to#105582
On Wed, 23 Mar 2016 21:17:57 -0500, Wildman via Python-list
<python-list@python.org> declaimed the following:

>
>I was referring to procedures called by a button click as
>opposed to a procedure calledd from elsewhere in the code.
>I guess there is no difference.  I assume that is what you
>meant.

	I'd have to see /how/ it is called. The "button click" is an event
handled by the GUI framework, to which you've bound a handler. Such items
(which may be attached to resize, menu, text fields, etc.) would need the
structure the framework uses... So if a method of a class, that means a
first argument placeholder of "self", and most likely a second for some
"event" data structure. You'd have to check the documentation for what it
expects.

	callback by framework:	theButton.pressed((clock, x, y))
		defined as:				def pressed(self, event):
	(granted, having the mouse x/y coordinates may not mean much for a
screen button)

	callback by framework:	mouseHandler.move((clock, x, y, lmb, rmb, mmb))
		defined as:				def move(self, event):
	(xmb is left/right/middle mouse button state)


	But if it is not being called by the framework, the arrangement/number
of arguments is under your control. If it is a method of a class instance,
it will receive the instance object as the first argument:
object.method(arglist) => method(self, arglist) {where self IS object}.

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#105633

FromWildman <best_lay@yahoo.com>
Date2016-03-24 11:19 -0500
Message-ID<X5udnY9b3tM1jmnLnZ2dnUU7-V-dnZ2d@giganews.com>
In reply to#105603
On Thu, 24 Mar 2016 08:06:28 -0400, Dennis Lee Bieber wrote:

> On Wed, 23 Mar 2016 21:17:57 -0500, Wildman via Python-list
> <python-list@python.org> declaimed the following:
> 
>>
>>I was referring to procedures called by a button click as
>>opposed to a procedure calledd from elsewhere in the code.
>>I guess there is no difference.  I assume that is what you
>>meant.
> 
> 	I'd have to see /how/ it is called. The "button click" is an event
> handled by the GUI framework, to which you've bound a handler. Such items
> (which may be attached to resize, menu, text fields, etc.) would need the
> structure the framework uses... So if a method of a class, that means a
> first argument placeholder of "self", and most likely a second for some
> "event" data structure. You'd have to check the documentation for what it
> expects.
> 
> 	callback by framework:	theButton.pressed((clock, x, y))
> 		defined as:				def pressed(self, event):
> 	(granted, having the mouse x/y coordinates may not mean much for a
> screen button)
> 
> 	callback by framework:	mouseHandler.move((clock, x, y, lmb, rmb, mmb))
> 		defined as:				def move(self, event):
> 	(xmb is left/right/middle mouse button state)
> 
> 
> 	But if it is not being called by the framework, the arrangement/number
> of arguments is under your control. If it is a method of a class instance,
> it will receive the instance object as the first argument:
> object.method(arglist) => method(self, arglist) {where self IS object}.

I believe I understand.  Thanks.  If you can't tell, I'm new to
Python so the learning process is on-going.

-- 
<Wildman> GNU/Linux user #557453
The cow died so I don't need your bull!

[toc] | [prev] | [next] | [standalone]


#105675

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2016-03-24 21:43 -0400
Message-ID<mailman.127.1458870167.2244.python-list@python.org>
In reply to#105633
On Thu, 24 Mar 2016 11:19:52 -0500, Wildman via Python-list
<python-list@python.org> declaimed the following:

>
>I believe I understand.  Thanks.  If you can't tell, I'm new to
>Python so the learning process is on-going.

	And you decided to throw in a GUI framework at the same time...

	I've only written one program using Tkinter (and I stuck the old PMW
library on top of that) -- it was quite horrid of a program. I have used
the file-requester in a few others though, but that is a stand-alone
widget/dialog.

	My only other GUI experience is a rudimentary "Jeopardy" framework
(called Jeparody -- did not include timers and player buttons) done on a
whim for an investment mailing list, using VB6... And a significant
application in which I emulated the display features of a Ramtek 9300
graphics engine using DECWindows with Graphical Kernel System on top (and
no "GUI Builder" -- just a hand-written GUI description file).

	I'd recommend going through the Python Tutorial, study the standard
types in the Library manual, and maybe skim through the Python Reference...
THEN maybe consider a GUI...

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#105678

FromWildman <best_lay@yahoo.com>
Date2016-03-24 23:37 -0500
Message-ID<Ju-dnWOBjbA_XWnLnZ2dnUU7-amdnZ2d@giganews.com>
In reply to#105675
On Thu, 24 Mar 2016 21:43:26 -0400, Dennis Lee Bieber wrote:

> On Thu, 24 Mar 2016 11:19:52 -0500, Wildman via Python-list
> <python-list@python.org> declaimed the following:
> 
>>
>>I believe I understand.  Thanks.  If you can't tell, I'm new to
>>Python so the learning process is on-going.
> 
> 	And you decided to throw in a GUI framework at the same time...

Coming from VB6, it seemed the natural thing to do.

> 	I've only written one program using Tkinter (and I stuck the old PMW
> library on top of that) -- it was quite horrid of a program. I have used
> the file-requester in a few others though, but that is a stand-alone
> widget/dialog.

I am a hobby programmer so I do this just for the pleasure of
creating something.  I started with 16bit assembly back in the
day and from there went to various flavors of BASIC including
PowerBASIC and Visual Basic.  Never made the transition to .net.
Didn't see a need.  I have yet to find anything that I can't do
with Classic VB6 that I want to do.

> 	My only other GUI experience is a rudimentary "Jeopardy" framework
> (called Jeparody -- did not include timers and player buttons) done on a
> whim for an investment mailing list, using VB6... And a significant
> application in which I emulated the display features of a Ramtek 9300
> graphics engine using DECWindows with Graphical Kernel System on top (and
> no "GUI Builder" -- just a hand-written GUI description file).
> 
> 	I'd recommend going through the Python Tutorial, study the standard
> types in the Library manual, and maybe skim through the Python Reference...
> THEN maybe consider a GUI...

Good advice.  I have found some good tuts on Youtube for Python
and Tk.  That gave me a good start.  And I have several websites
bookmarked for other tutorials and references.  Plus that several
knowledgeable people right here who are willing to help.

-- 
<Wildman> GNU/Linux user #557453
"Be at war with your vices, at peace with your neighbors,
and let every new year find you a better man."
  -Benjamin Franklin

[toc] | [prev] | [next] | [standalone]


#105695

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2016-03-25 12:50 -0400
Message-ID<mailman.5.1458924612.28225.python-list@python.org>
In reply to#105678
On Thu, 24 Mar 2016 23:37:54 -0500, Wildman via Python-list
<python-list@python.org> declaimed the following:

>
>Coming from VB6, it seemed the natural thing to do.
>
	Have you ever looked at a module/form file using a Non VS editor? Where
you can see the actual text definition of the form?

	Visualize writing ~2500 lines of such form definitions by hand -- and
some 2000 lines of corresponding C code referencing it. That was the
DECWindow UIL file for that graphics application I mentioned. Oh -- and it
was just for ONE "window" with a few utility menus (the graphics emulation
was just that -- a display app that other applications sent drawing
commands to). That was back in 1990. I couldn't rewrite the real
application as it was a text-based form handler (the main executable read a
data file that had templates for each data screen, and a definition of the
fields on the screen, a list of sub-applications and which screens applied
to them -- and when one said "go" to a sub-application it would spawn a new
program that did just the one number-crunching task sending drawing
commands to the display, then exit so one could pick another
sub-application for the next bit of display work; would have required a
complete rewrite into a single huge executable in order to directly drive
windows, instead of using sub-applications that were loaded on demand)

	Since there aren't any real GUI designers for Python (there are some
that generate a layout file, but they are also specific to particular
frameworks so picking one gets contentious).

>
>I am a hobby programmer so I do this just for the pleasure of
>creating something.  I started with 16bit assembly back in the
>day and from there went to various flavors of BASIC including
>PowerBASIC and Visual Basic.  Never made the transition to .net.
>Didn't see a need.  I have yet to find anything that I can't do
>with Classic VB6 that I want to do.
>
	I used to have a paid edition of VB6, but now live with (and don't use)
Visual Studio Express releases (2010: where VB.net, C#, and C++ were each
separate IDEs; 2012: all three in one master; as I recall, there had been
some controversy that M$ didn't want to release a new VS for Windows 7 and
earlier -- wanting to focus on the "app" style of Windows 8)

	My work doesn't use them... Some have used it for data-analysis stuff
but the core work is either Ada or C (VxWorks-based) -- so again no GUI
builders and barely anything in the way of an IDE (one project used Eclipse
for editing, but still invoked external shell scripts to drive the build
system). I've used Python for data-analysis stuff (ugliest being a program
to take a pair of Wireshark capture files [sent packets on NIC-a, received
packets on NIC-b], match up the data and write a database with the
sent/received timestamps and packet ID... then export the database for use
in Excel plotting. All command line driven...


>
>Good advice.  I have found some good tuts on Youtube for Python
>and Tk.  That gave me a good start.  And I have several websites
>bookmarked for other tutorials and references.  Plus that several
>knowledgeable people right here who are willing to help.

	When I mention "Python Tutorial" I meant the document that used to be
included with any Python installer. It was a PDF file ages ago, not sure
what Python.org uses now... I've used ActiveState builds for decades now,
and they include the tutorial in a Windows Help file that contains all the
standard documentation (Tutorial, Language Ref, Library Ref, a lot of the
PEP texts, additional stuff).

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#105508

FromTerry Reedy <tjreedy@udel.edu>
Date2016-03-22 23:52 -0400
Message-ID<mailman.28.1458705193.2244.python-list@python.org>
In reply to#105506
On 3/22/2016 10:46 PM, Wildman via Python-list wrote:
> Platform: Linux
> Python: v.2.7.9
> Tkinter: v.8.6.2
>
> My program has some buttons for file operations, load_image,
> save_image, and quit.  I would like to bind a key that will
> execute the procedures for each of the buttons.  The binding
> for the quit button was easy...
>
> root.bind("<q>", quit)
> root.bind("<Q>", quit)
>
> That works but it not executing a quit button procedure.
> It is merely executing an internal command.  My problem is
> calling an actual button procedure.  Over the last several
> hours I have tried many different syntax arrangements and
> I keep getting "object not defined" errors.  I also tried
> placing the bind statements into other places in the code.
> I have run out of ideas.
>
> Below is a basic skeleton of my code.  Any help appreciated.
>
> #!/usr/bin/env python
>
> try:
>      import Tkinter as tk
>      from Tkinter import Tk

The second import is not needed.  tk.Tk is short and should be called 
just once.

> except ImportError:
>      import tkinter as tk
>      from tkinter import Tk

ditto.

> import tkFileDialog, tkMessageBox

These are 2.x only and should be after the Tkinter import.
For 3.x, import tk.filedialog, tk.messagebox

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#105511

FromWildman <best_lay@yahoo.com>
Date2016-03-22 23:30 -0500
Message-ID<L6KdnXUY771Mhm_LnZ2dnUU7-QMAAAAA@giganews.com>
In reply to#105508
On Tue, 22 Mar 2016 23:52:57 -0400, Terry Reedy wrote:

> On 3/22/2016 10:46 PM, Wildman via Python-list wrote:
>> Platform: Linux
>> Python: v.2.7.9
>> Tkinter: v.8.6.2
>>
>> My program has some buttons for file operations, load_image,
>> save_image, and quit.  I would like to bind a key that will
>> execute the procedures for each of the buttons.  The binding
>> for the quit button was easy...
>>
>> root.bind("<q>", quit)
>> root.bind("<Q>", quit)
>>
>> That works but it not executing a quit button procedure.
>> It is merely executing an internal command.  My problem is
>> calling an actual button procedure.  Over the last several
>> hours I have tried many different syntax arrangements and
>> I keep getting "object not defined" errors.  I also tried
>> placing the bind statements into other places in the code.
>> I have run out of ideas.
>>
>> Below is a basic skeleton of my code.  Any help appreciated.
>>
>> #!/usr/bin/env python
>>
>> try:
>>      import Tkinter as tk
>>      from Tkinter import Tk
> 
> The second import is not needed.  tk.Tk is short and should be called 
> just once.
> 
>> except ImportError:
>>      import tkinter as tk
>>      from tkinter import Tk
> 
> ditto.
> 
>> import tkFileDialog, tkMessageBox
> 
> These are 2.x only and should be after the Tkinter import.
> For 3.x, import tk.filedialog, tk.messagebox

Thanks for the info.  Making the changes...

-- 
<Wildman> GNU/Linux user #557453
The cow died so I don't need your bull!

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web