Path: csiph.com!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'else:': 0.03; 'root': 0.04; 'cc:addr:python-list': 0.09; "'n'": 0.09; 'rows': 0.09; 'def': 0.13; 'columns': 0.16; 'tkinter.': 0.16; 'widget': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'arguments': 0.22; 'delay': 0.22; 'pass': 0.22; 'header:In-Reply-To:1': 0.24; 'command': 0.26; 'skip:# 10': 0.27; 'message-id:@mail.gmail.com': 0.27; 'subject:/': 0.30; 'code': 0.30; "can't": 0.32; 'scanned': 0.32; 'displayed': 0.33; 'wrap': 0.33; 'received:google.com': 0.35; 'step': 0.36; 'but': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'button': 0.38; 'skip:p 20': 0.38; 'where': 0.40; 'called': 0.40; 'some': 0.40; 'avoid': 0.61; 'our': 0.64; 'photo': 0.81; 'subject:get': 0.81; 'interrupt': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=B9YPuretqtYp2qFQl4zAJ3C58qBOnsnxwg+frKWMK0M=; b=ZhxzJfcIBGtG096tch5k/jaKn1/0WK3kD8qJmLGKqDFjhqOXSbYGkhps3XBykWkFIz dvnFK9+LEvsdMe6PMI+mKaK0dttxzrgFTxfsaW/sooP4cGy6ONOHRvxPZ8LDKMAX39uP Rm8a/BByroB+r9PI7GVAJT8/fAXWMovWELKlj3HmSb0Qgy8zaNs+lA74nOWPVpnpx5JI 6ELbXXLsfu1Ij2L3XY3vePhONwWMJ/uDSHhZ25HfcQX8sBwuqLCBzlilxBRcSvF1JTTp CVnLsGogCGBXIXYpYJc/xTtTLiYRDS/s78vagS+pRLPDvEqg5bpv3ACIdQI72Ss2d62w Q06g== MIME-Version: 1.0 X-Received: by 10.182.165.131 with SMTP id yy3mr4511306obb.49.1445391887964; Tue, 20 Oct 2015 18:44:47 -0700 (PDT) In-Reply-To: References: Date: Tue, 20 Oct 2015 18:44:47 -0700 Subject: Re: 2.7.9: PhotoImage get/put From: C Smith To: Emile van Sebille Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1445391898 news.xs4all.nl 23769 [2001:888:2000:d::a6]:53017 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:97851 >> def process(): # Ordinarily this would be process(photo,wdth,hgt) >> global wdth # but I ran into problems calling it from a button If you want to pass arguments to a command called when a button is clicked, you have to use 'lambda' in tkinter. >> global hgt #command with parameters... >> global photo # the PhotoImage displayed by the calling code >> >> # indents set to 1 to avoid word wrap >> >> # Loop through rows and columns of the image >> v=wdth >> z=0 >> a=-1 >> for y in range (0,hgt): >> w=v >> v=z # swap v and z so rows are scanned l/r r/l l/r >> z=w >> a=-a # set our inc/dec step for lr->rl scan >> >> for x in range(v,z,a): >> pix = photo.get(x,y) if pix == u'0 0 0' : >> #pixel_turn_on() >> photo.put("#%02x%02x%02x" % (255,255,255), (x,y)) >> else: >> #pixel_turn_off() >> photo.put("#%02x%02x%02x" % (0,0,0), (x,y)) You can't expect a delay to happen during the mainloop() of the program. To interrupt the mainloop(), use: parent.after(n,someCommand) Where 'n' is some amount of milliseconds. Just have the parent widget or the root frame call it.