top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

Non object oriented use of Tkinter in python?

+2 votes
120 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 Google+ Share Button LinkedIn Share Button Multiple Social 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.

+2 votes

If I have a string that is python code, for example

mycode = "print('hello world')"
myresult = "hello world"

How can a "manually" build a unittest (doctest) and test I get myresult

I have attempted to build a doctest but that is not working.

e = doctest.Example(source="print('hello world')/n", want="hello worldn")
t = doctest.DocTestRunner()
t.run(e)
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...