Results 1 to 3 of 3

Thread: Python (Tkinter) sintakse, Button status

  1. #1
    Pieredzējis lietpratējs DevilDriver's Avatar
    Join Date
    21-07-09
    Posts
    1,141
    Rep Power
    175

    Default Python (Tkinter) sintakse, Button status

    Bvakar,

    Aiz neko darīt lēnām rušinos pa Python + Raspberry, nevaru izdomāt (lasīt = nemāku sagooglēt ) kā no Tkinter moduļa izdabūt ārā radiopogas statusu, kuru izmantot kā On/Off Pi izejām -

    Respektīvi kā sintaksē noteikt kad radiopoga ir nospiesta / vai atlaista.

    Esošais kods ir šāds :


    from tkinter import

    master = Tk()

    def ON_S1():
    (GPIO.output(3, GPIO.LOW))
    def ON_S2():
    (time.sleep(0.1))
    def ON_S3():
    (GPIO.output(3, GPIO.HIGH))


    b = Button(master, text="Motor ON", command=lambda:[ON_S1(), ON_S2(), ON_S3()])
    b.pack()

    def CL():
    (GPIO.cleanup())

    c = Button(master, text="Clear", command=CL)
    c.pack()

    Visual Basic valodā ja nemaldos bija tieši arguments #If_Button=Pressed , iekš Python nemāku atrast.

  2. #2

    Default

    Man kaut kādā vecā projektā bija šādi:

    cond_value = 0

    self.conditionvar = tk.IntVar()
    self.conditionvar.set(cond_value)
    self.radiobutton_condition = tk.Radiobutton(self, text='New', variable=self.conditionvar, value=0).place(x=90, y=40)
    self.radiobutton_condition = tk.Radiobutton(self, text='Used', variable=self.conditionvar, value=1).place(x=140, y=40)
    [Pending]

  3. #3
    Pieredzējis lietpratējs DevilDriver's Avatar
    Join Date
    21-07-09
    Posts
    1,141
    Rep Power
    175

    Default

    Izdarījos kodā šādi, ja nu kādam noder :

    Manām vajadzībām strādā perfektum

    import RPi.GPIO as GPIO
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(3, GPIO.OUT)
    GPIO.output(3, GPIO.HIGH)
    import time
    import tkinter

    def ON_S1():
    (GPIO.output(3, GPIO.LOW))
    def OFF_S1():
    (GPIO.output(3, GPIO.HIGH))

    def button_down(event):
    global buttonpressed
    ON_S1()
    print('MOTOR ON')
    buttonpressed = True


    def button_up(event):
    global buttonpressed
    OFF_S1()
    print('MOTOR OFF')
    buttonpressed = False




    master = tkinter.Tk()
    w = tkinter.Button(master, text="MOTOR ON/OFF")
    w.bind('<ButtonPress>', button_down)
    w.bind('<ButtonRelease>', button_up)
    w.pack()

    master.mainloop()

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •