Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.04; 'argument': 0.05; 'advocate': 0.07; 'class,': 0.07; 'suggestions,': 0.07; 'tkinter': 0.07; 'buttons': 0.09; 'preferable': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'spaces': 0.09; 'used.': 0.09; 'width': 0.09; 'python': 0.11; 'gui': 0.12; 'jan': 0.12; 'arg': 0.16; 'blocks': 0.16; 'chunks': 0.16; 'easier.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'somehow,': 0.16; 'styling': 0.16; 'subject:comment': 0.16; 'subject:program': 0.16; 'tkinter.': 0.16; 'url:pep-0008': 0.16; 'url:peps': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'do.': 0.18; 'all,': 0.19; 'bit': 0.19; 'app': 0.19; 'any,': 0.19; 'subject:] ': 0.20; 'code,': 0.22; 'import': 0.22; 'separate': 0.22; 'header:User-Agent:1': 0.23; 'url:dev': 0.24; 'looks': 0.24; 'skip:" 30': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'besides': 0.30; 'code': 0.31; '3.x': 0.31; 'jean': 0.31; 'url:python': 0.33; 'skip:# 10': 0.33; 'style': 0.33; 'comment': 0.34; 'agree': 0.35; 'but': 0.35; 'add': 0.35; 'there': 0.35; 'method': 0.36; 'url:org': 0.36; 'changing': 0.37; 'to:addr :python-list': 0.38; 'does': 0.39; 'bad': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'even': 0.60; 'read': 0.60; 'future': 0.60; 'break': 0.61; 'conversion': 0.61; 'skip:t 30': 0.61; 'received:173': 0.61; 'simple': 0.61; 'show': 0.63; 'such': 0.63; 'dear': 0.65; 'here': 0.66; 'line,': 0.68; 'saving': 0.69; 'led': 0.72; '"not': 0.84; 'calls,': 0.84; 'received:fios.verizon.net': 0.84; 'sliders': 0.84; 'imagine': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: [newbie] advice and comment wanted on first tkinter program Date: Fri, 17 Jan 2014 16:40:42 -0500 References: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-254-207.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 65 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389994858 news.xs4all.nl 2879 [2001:888:2000:d::a6]:35384 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64197 On 1/17/2014 8:20 AM, Jean Dupont wrote: > Dear all, > I made a simple gui with tkinter. I can imagine there are things which I > did which are "not optimal". So what I ask is to comment on my code > preferable with snippets of code which show how to do improve my code. > #!/usr/bin/env python > import Tkinter 1. import Tkinter as tk Besides saving a bit of writing and reading time later, this makes any future conversion to 3.x easier. import tkinter as tk 2. add a few spaces to demarcate blocks of code. > import time > import RPi.GPIO as GPIO 2. add a few spaces to demarcate blocks of code, such as here > GPIO.setmode(GPIO.BOARD) > GPIO.setup(26,GPIO.OUT) > GPIO.setup(24,GPIO.OUT) > #hardware : connect 2 leds: > #board-pin 26 on/off led; control with buttons > #board-pin 24 led with pwm dimming and frequency; control via sliders and here > top = Tkinter.Tk() > top.geometry("600x400+310+290") This looks strange somehow, but if it works... > label1 = Label(top,relief=RAISED,bg = > "#EFF980",font=("Helvetica",14),height = 1, width = 15) In calls, put spaces after , but not before and after =. For other suggestions, see http://www.python.org/dev/peps/pep-0008/ I suspect that the above is one line in your code and the bad wrapping a result of mis-spacing. The following is also one line, but easer to read as spaces separate argument chunks label1 = Label(top, relief=RAISED, bg="#EFF980", font=("Helvetica",14), height=1, width=15) and the wrapping, if any, does not break up an arg chunk. Some people advocate defining an App class, but Tk and tkinter, even though object method based, allow the straightforward imperative style you have used. I agree with Peter: "First and foremost a program has to do what the author wants it to do. Everything else is secondary." But a bit of styling will make reading and changing easier. -- Terry Jan Reedy