top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Non object oriented use of Tkinter in python?

+2 votes
532 views

I'm trying out Tkinter with the (non object oriented) code fragment below: It works partially as I expected, but I thought that pressing "1" would cause the program to quit, however I get this message:

TypeError: quit() takes no arguments (1 given),

I tried changing quit to quit() but that makes things even worse. So my question: can anyone here help me
debug this?

#!/usr/bin/env python
import Tkinter as tk
def quit():
 sys.exit()
root = tk.Tk()
label = tk.Label(root, text="Hello, world")
label.pack()
label.bind("", quit)
root.mainloop()
posted Dec 6, 2013 by Anderson

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

the engine is probably passing an argument to your quit callback method.Try

def quit(param):
 sys.exit(str(param))

You probably don't even care about the parameter:

def quit(param):
 sys.exit()
answer Dec 6, 2013 by Kumar Mitrasen
+1 vote

I don't know the details of the Tkinter library, but you could find out what quit is being passed by modifying it to take a single parameter and printing it out (or using pdb):

 def quit(param):
 print(param)
 sys.exit()

Having taken a quick look at the documentation, it looks like event handlers (like your quit function) are passed the event that triggered them. So you can probably just ignore the parameter:

 def quit(_):
 sys.exit()
answer Dec 6, 2013 by Deepak Dasgupta
Similar Questions
+2 votes

I have a Tkinter app that can optionally label some buttons with certain Unicode glyphs that aren't always available (depending on the OS, etc.).

When they aren't available, Tkinter renders them as "uNNNN". What I'd like to do is check whether the glyphs are available, and fall back to my own alternate text for the button if not. Can I do this?

I'd also like to do the same in pygtk.

+1 vote

Can someone please explain data hiding in python through a program ?

0 votes

Can python sockets be used to capture IP traffic when the traffic is originating from a non-python source?

Using a Lantronix UDS-1100 serial to IP converter. The goal is to write a small proof of concept piece in Python to capture serial data output by this device over IP.

I've done a couple test projects using sockets in python, but they were all done between python processes (python > python): listen() on one end, and connect(), sendall() etc on the other.

I think I can use sockets for this project, but before I invest a bunch of time into it, wanted to make sure it is a viable solution.

Can python sockets be used to capture IP traffic when the traffic is originating from a non-python source? I have full control over the IP and port that the device sends the serial data to, but there will be no python connect() initiated by the client. I can pre-pend then serial data with some connect() string if needed.

If sockets won't work, please recommend another solution...guessing it will be REST or similar.

0 votes

I am to start a new free-time project in the next couple of weeks. I am ready to use open accessible Python modules not wanting to reinvent the wheel :-)

Is there any repository where I can find Python modules not being part of the standard distribution? I have some hits by Google but that seems to be far from complete.

0 votes

I need to print the Dictionary in a detailed way.

Current When am print the dictionary am getting like below.

<Details.Value: object at 0x0000027062245160>
...