Appropriate way to quit Tkinter
I've just started playing with Python. Installed 2.5 on Windows XP system. I'm working through some of the examples in Programming Python 3ed by Mark Lutz. Given the following example when the Quit All button action is assigned to root.quit the windows aren't dismissed or destroyed. The application appears to terminate, but the windows remain. When the action is assigned to root.destroy, the windows are closed. Questions: 1) Which way is preferred / correct? 2) Is something wrong with 2.5? (I haven't tried older versions of python) 3) Is there something wrong with my installation? # # popup three new window, with style # destroy() kills one window, quit() kills all windows and app; top-level # windows have title, icon, iconify/deiconify and protocol for wm events; # there always is an app root window, whether by default or created as an # explicit Tk() object; all top-level windows are containers, but never # packed/gridded; Toplevel is like frame, but new window, and can have menu; # from Tkinter import * root = Tk() # explicit root trees = [('The Larch!', 'light blue'), ('The Pine!', 'light green'), ('The Giant Redwood!', 'red')] for (tree, color) in trees: win = Toplevel(root) # new window win.title('Sing...') # set border win.protocol('WM_DELETE_WINDOW', lambda:0) # ignore close win.iconbitmap('py-blue-trans-out.ico')# not red Tk msg = Button(win, text=tree, command=win.destroy) # kills one win msg.pack(expand=YES, fill=BOTH) msg.config(padx=10, pady=10, bd=10, relief=RAISED) msg.config(bg='black', fg=color, font=('times', 30, 'bold italic')) root.title('Lumberjack demo') Label(root, text='Main window', width=30).pack() #Button(root, text='Quit All', command=root.quit).pack() # kills all app Button(root, text='Quit All', command=root.destroy).pack() # kills all app root.mainloop() -- http://mail.python.org/mailman/listinfo/python-list
Re: Appropriate way to quit Tkinter
Fredrik Lundh wrote: [snip] > works for me. are you perhaps running this under some kind of IDE that > keeps the process running even after the program has terminated? > It works the same way if I run from IDLE or from the DOS command prompt. -- http://mail.python.org/mailman/listinfo/python-list
Re: Appropriate way to quit Tkinter
Fredrik Lundh wrote: > mzdude wrote: > > >> works for me. are you perhaps running this under some kind of IDE that > >> keeps the process running even after the program has terminated? > >> > > It works the same way if I run from IDLE or from the DOS command prompt. > > I find very hard to believe that a Python interpreter run from the DOS > command prompt wouldn't terminate when it reaches the end of the main > program. > > what Python distribution are you using? > > Not sure I understand the question. I downloaded python-2.5.msi from python.org/download. >From the IDLE Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: find sublist inside list
On May 4, 9:01 am, Matthias Gallé wrote: > bearophileh...@lycos.com wrote: > > John O'Hagan: > >> li=['a', 'c', 'a', 'c', 'c', 'g', 'a', 'c'] > >> for i in range(len(li)): > >> if li[i:i + 2] == ['a', 'c']: > >> li[i:i + 2] = ['6'] > > > Oh well, I have done a mistake, it seems. > > Another solution then: > > 'acaccgac'.replace("ac", chr(6)) > > '\x06\x06cg\x06' > > > Bye, > > bearophile > > Thanks bearophile and John for your quick answers. > Unfortunately, the int that can replace a sublist can be > 255, but > John's answer looks simple and good enough for me. I will use it as a > starting point. > substring isn't limited to 0..255 >>> substring = "\0x%d\0x%d" % (257,257) >>> 'acaccgac'.replace("ac", substring) '\x00x257\x00x257\x00x257\x00x257cg\x00x257\x00x257' -- http://mail.python.org/mailman/listinfo/python-list
Re: find sublist inside list
On May 4, 4:54 pm, "Gabriel Genellina" wrote: > En Mon, 04 May 2009 15:12:41 -0300, mzdude escribió: > > > substring isn't limited to 0..255 > >>>> substring = "\0x%d\0x%d" % (257,257) > >>>> 'acaccgac'.replace("ac", substring) > > '\x00x257\x00x257\x00x257\x00x257cg\x00x257\x00x257' > > This isn't what you think it is. Look carefully: > > py> substring = "\0x%d\0x%d" % (257,257) > py> len(substring) > 10 > py> list(substring) > ['\x00', 'x', '2', '5', '7', '\x00', 'x', '2', '5', '7'] > > -- > Gabriel Genellina OOPS. My bad. But I'm not going to give up. l = ['a','b','c','a','c'] us = unicode("".join(l)) substr = unichr(257) + unichr(257) us = us.replace(u'ac',substr) print len(us) print list(us) output is >>> 5 [u'a', u'b', u'c', u'\u0101', u'\u0101'] -- http://mail.python.org/mailman/listinfo/python-list
Retrieving BSTR * from a DLL
I need to interface with a windows DLL that has the following signature extern "C" void Foo( BSTR in, BSTR *out ) Code so far >>> from ctypes import * >>> import comtypes >>> LPBSTR = POINTER(comtypes.BSTR) >>> >>> hdl = windll.MyDll.Foo >>> hdl.rettype = None >>> hdl.argtypes = [comtypes.BSTR, LPBSTR] >>> >>> inStr = comtypes.BSTR(u'Some Silly String') >>> out = comtypes.BSTR >>> >>> hdl(inStr,byref(out)) Traceback (most recent call last): File "", line 1, in hdl(inStr,byref(out)) TypeError: byref() argument must be a ctypes instance, not '_ctypes.SimpleType' Also tried the following >>> out = comtypes.BSTR(u'') >>> p = pointer(out) >>> hdl(inStr,p) Traceback (most recent call last): File "", line 1, in hdl(inStr,p) ValueError: Procedure probably called with too many arguments (8 bytes in excess) Any feedback would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: Retrieving BSTR * from a DLL
On Jul 10, 6:15 am, Andrew MacIntyre <[EMAIL PROTECTED]> wrote: > This likely indicates that the DLL is using the C calling convention > and not the stdcall calling convention. Use CDLL rather than WinDLL > to load the DLL. using cdll got me over the calling hurdle. However, I'm not seeing the returned BSTR. > You might like to join the ctypes-users mailing list at sourceforge. I did, thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Request Help Debugging Program
On Jul 23, 6:30 pm, Samir <[EMAIL PROTECTED]> wrote: > Hi Everyone, > > > def findSumOfDivisor(n): > return sum(divisor) # fine using function sum() > > sum = findSumOfDivisor(i) # then find the sum of its divisors oops redefine what sum is. >>> x = [1,2] >>> sum(x) 3 >>> sum = 4 >>> sum(x) Traceback (most recent call last): File "", line 1, in sum(x) TypeError: 'int' object is not callable >>> -- http://mail.python.org/mailman/listinfo/python-list
Re: how to stop a function execution like...
On Jun 16, 7:30 am, Gaudha wrote: > Is there any built-in function to stop execution of a function similar > to stop the program execution by sys.exit? > In the example below, I want to skip statement 2... if the 'if' > condition is satisfied. > Don't advice me to put statement 2 in 'else' block. That's not my > intention. > May be this a simple task. Sorry to say I'm novice in Python, > gentlemen... > > def funct : > if (.) : statement 1 > statement 2 sys.exit is a pretty harsh way to stop execution. It usually means unable to continue. There is nothing that stops you from putting that in a function. Another possiblity would be def funct : if( ) : statement 1 raise UserWarning, "precondition X in funct not met" statement 2 ... statement n Check out the try / except docs. -- http://mail.python.org/mailman/listinfo/python-list