Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64164

[newbie] advice and comment wanted on first tkinter program

Newsgroups comp.lang.python
Date 2014-01-17 05:20 -0800
Message-ID <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> (permalink)
Subject [newbie] advice and comment wanted on first tkinter program
From Jean Dupont <jeandupont115@gmail.com>

Show all headers | View raw


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
import time
import RPi.GPIO as GPIO
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
top = Tkinter.Tk()
top.geometry("600x400+310+290")
var1 = DoubleVar()
var2 = DoubleVar()
i=0
p=GPIO.PWM(24,1)
p.start(50)
def btn_on_cmd():
        text3.configure(bg = "#00FF00")
        text3.delete(0.1,END)
        text3.insert("0.1","ON ")
        GPIO.output(26,True)
def btn_off_cmd():
        text3.configure(bg = "#FF4000")
        text3.delete(0.1,END)
        text3.insert("0.1","OFF")       
        GPIO.output(26, False)
def timer0():
        global i
        i=i+1
        text1.delete(0.1,END)
        text1.insert(4.2,"Timer: " + str(i))
        label1.configure(text=time.strftime("%H:%M:%S"))
        top.after(1000, timer0)
def Set_PWM(var1):
        DC = float(var1)
        p.ChangeDutyCycle(DC)
def Set_FREQ(var2):
        FR = float(var2)
        p.ChangeFrequency(FR)   
btn_on = Button(top, text ="On", command = btn_on_cmd)
btn_on.place(x=10,y=100)
btn_off = Button(top, text ="Off", command = btn_off_cmd)
btn_off.place(x=100,y=100)
text1 =Text(top, bg = "#009BFF", font=("Helvetica",14), height = 1, width
= 15)
text1.place(x=5,y=5)
text3=Text(top, bg = "red", font=("Helvetica",12),height = 1, width = 4) 
text3.place(x=60,y=60)
label1 = Label(top,relief=RAISED,bg =
"#EFF980",font=("Helvetica",14),height = 1, width = 15)
label1.place(x=5,y=350)
label2= Label(top,relief=RAISED,bg =
"#BFBFBF",font=("Helvetica",10),height = 1, text= "Freq (Hz)")
label2.place(x=420,y=320)
label3= Label(top,relief=RAISED,bg =
"#BFBFBF",font=("Helvetica",10),height = 1, text= "DC %")
label3.place(x=520,y=320)
slider1 = Scale(top,variable = var1,length = 300,resolution = 1,command  =
Set_PWM)
slider1 = Scale(top,variable = var1,length = 300,resolution = 1,command  = Set_PWM)
slider1.place(x=500,y=5)
slider1.set(50)
slider2 = Scale(top,variable = var2,length = 300,from_= 0.1, to = 50,resolution = 0.1,command  = Set_FREQ)
slider2.place(x=400,y=5)
slider2.set(2)
timer0()
top.mainloop()
GPIO.cleanup()


thanks in advance 
jean

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[newbie] advice and comment wanted on first tkinter program Jean Dupont <jeandupont115@gmail.com> - 2014-01-17 05:20 -0800
  Re: [newbie] advice and comment wanted on first tkinter program Peter Otten <__peter__@web.de> - 2014-01-17 16:17 +0100
  Re: [newbie] advice and comment wanted on first tkinter program Terry Reedy <tjreedy@udel.edu> - 2014-01-17 16:40 -0500
    Re: [newbie] advice and comment wanted on first tkinter program Jean Dupont <jeandupont314@gmail.com> - 2014-01-18 06:52 -0800
      Re: [newbie] advice and comment wanted on first tkinter program Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-01-18 15:12 +0000
        Re: [newbie] advice and comment wanted on first tkinter program Jean Dupont <jeandupont314@gmail.com> - 2014-01-19 20:04 -0800
          Re: [newbie] advice and comment wanted on first tkinter program Chris Angelico <rosuav@gmail.com> - 2014-01-20 17:24 +1100
            Re: [newbie] advice and comment wanted on first tkinter program Jean Dupont <jeandupont314@gmail.com> - 2014-01-21 23:23 -0800
              Re: [newbie] advice and comment wanted on first tkinter program Dave Angel <davea@davea.name> - 2014-01-22 07:08 -0500
          Re: [newbie] advice and comment wanted on first tkinter program Alister <alister.ware@ntlworld.com> - 2014-01-20 09:17 +0000
            Re: [newbie] advice and comment wanted on first tkinter program Jean Dupont <jeandupont115@gmail.com> - 2014-01-22 06:45 -0800
              Re: [newbie] advice and comment wanted on first tkinter program Alister <alister.ware@ntlworld.com> - 2014-01-22 15:43 +0000
                Re: [newbie] advice and comment wanted on first tkinter program Jean Dupont <jeandupont115@gmail.com> - 2014-01-27 00:23 -0800
              Re: [newbie] advice and comment wanted on first tkinter program Jean Dupont <jeandupont115@gmail.com> - 2014-01-27 00:28 -0800
      Re: [newbie] advice and comment wanted on first tkinter program Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-18 16:15 +0000
      Re: [newbie] advice and comment wanted on first tkinter program Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-01-18 12:28 -0500
      Re: [newbie] advice and comment wanted on first tkinter program Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-01-18 13:54 -0500
      Re[2]: [newbie] advice and comment wanted on first tkinter program Grawburg <grawburg@myglnc.com> - 2014-01-18 13:49 -0500

csiph-web