Jump to content
View in the app

A better way to browse. Learn more.

Tinkerunity

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Geschrieben

Hallo,

 

ich habe mich mal an Python versucht um auf meinem Raspberry Pi ein GUI zu erstellen. Beim starten des Scripts bekomme ich aber die folgende Fehlermeldung:

File "GUI.py", line 24

  ipcon = IPConnection() # Create IP connection

      ^

IndentationError: expected an indented block

 

HOST = "127.0.0.1"
PORT = 4223
UID = "jNw"

from Tkinter import *
from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_remote_switch import RemoteSwitch
import os
master = Tk()

master.title("GUI")

w = Canvas(master, width=300, height=200)
w.pack()

def shutdown():
    os.system("sudo shutdown -h now")

def reboot():
    os.system("sudo shutdown -r now")

def light_on():
    if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    rs = RemoteSwitch(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Switch socket with house code 17 and receiver code 1 on.
    # House code 17 is 10001 in binary (least-significant bit first)
    # and means that the DIP switches 1 and 5 are on and 2-4 are off.
    # Receiver code 1 is 10000 in binary (least-significant bit first)
    # and means that the DIP switch A is on and B-E are off.
    rs.switch_socket_b(1, 1, RemoteSwitch.SWITCH_TO_ON)

def light_off():
    if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    rs = RemoteSwitch(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Switch socket with house code 17 and receiver code 1 on.
    # House code 17 is 10001 in binary (least-significant bit first)
    # and means that the DIP switches 1 and 5 are on and 2-4 are off.
    # Receiver code 1 is 10000 in binary (least-significant bit first)
    # and means that the DIP switch A is on and B-E are off.
    rs.switch_socket_b(1, 1, RemoteSwitch.SWITCH_TO_OFF)

b=Button(master, text= "Shutdown", command=shutdown)
b.pack()

b=Button(master, text= "Reboot", command=reboot)
b.pack()

b=Button(master, text= "Licht an", command=light_on)
b.pack()

b=Button(master, text= "Licht aus", command=light_off)
b.pack()

mainloop()

 

Grüße

Geschrieben

Da stehen wahrscheinlich Leerzeichen vor, die da nicht hingehören. Versuche die mal weg zu machen. Leerzeichen vor Befehlen dürfen und müssen nur bei schleifen, if und try Anweisungen eingesetzt werden. Dort sind sie allerdings auch erforderlich damit python erkennt welche Befehle zu der entsprechenden Abfrage gehören.

Geschrieben

Ich erkenne leider da kein überflüssiges Leerzeichen im Code.

Geschrieben

Oh du hast recht. Mein Fehler  ::). Du hast zu wenig! Du hast ja die Abfrage if __name__ usw.

 

Der Code darunter hat die gleiche Einrückung. Der muss weiter eingerückt werden, wenn er dazu gehören soll.

Geschrieben

Ich danke dir  :) Genau das wars das ist mir garnicht aufgefallen  ::)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Reply to this topic...

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.