Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have a raspberry Pi 2 Model B. I am trying to make a program that turns on an LED when the input is 'Yes'. What happens is that I get a syntax error saying that def was the error with the arrow pointing at the f. Here is my code:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(40, GPIO.OUT)
GPIO.setup(38, GPIO.OUT)
GPIO.output(38, 1)
def start():
main(input("> ")
def main(yn):
while True:
if yn == 'Yes':
GPIO.output(40, 1)
print("The LED is on!")
break
if yn == 'No':
GPIO.output(40, 0)
print("The LED is off!")
break
start()
start()
Please help and thank you in advance!
Your start function is missing a closing parenthesis:
def start():
main(input("> "))
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 11 months ago.
Improve this question
I am using pygame to create something and I need to have a delay for about 10 seconds that is interrupted when a button is pushed. When I tried to do this, it paused on the delay and it was unable to detect for button pushes. I was wondering if this is even possible or if there are any alternatives. I have tried:
pygame.time.delay(10000)
if hit1: #hit1 is a bool representing keydown
Blue1() #my function to draw a shape
I happened to have come across the same problem 2 years ago (when I was 12) so I think I understand what you mean.
First import sleep from time
from time import sleep
Then you can try this
#code before 10 sec count
interrupt = false
millisecondPassed = 0
while true:
sleep(0.01)
millisecondPassed += 1
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_b:
interrupt = true
if millisecondPassed >= 10000 or interrupt == true:
break
#code after interruption
As for reference:
10 seconds = 10000 milliseconds
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
from tkinter import *
root = Tk()
mylabel = label(root, text = "What's up?")
mylabel.pack()
root.mainloop()
This is the code I used in Visual code studio. And it shows me an error:
NameError: name 'label' is not defined
What do I need to change to make this work?
pls change your code like this
mylabel = Label(root,text = '')
you should use Lable instead label
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
from random import*
from tkinter import*
players=['wq','qwe','qwe']
players_to_random=[]
window = Tk()
window.title("Game is ON")
w= Label(window, bg="yellow")
def onclick():
players_to_random.append(text)
print(players_to_random)
def showButtons():
for i in players:
btn = Button(window, text=i command=onclick)
btn.pack(side=LEFT)
showButtons()
I get the Error command invalid syntax but as far as i know it is possible to use command as a parameter for Buttons.So why does it show this Error
Check the indentation and syntaxis in the whole shouButtons function.
The block of code in the for loop must be indented. Also there is a comma missing between Button parameters text and command.
def showButtons():
for i in players:
btn = Button(window, text=i, command=onclick)
btn.pack(side=LEFT)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I keep getting a syntax error in my code at elif not running: but I don't understand why. Everything seems to be formatted correctly, but yet I still get that syntax error.
running = True
def checker():
global running
if running:
if label.image == colorPhoto:
label.image = blackPhoto
label.configure(image = blackPhoto)
#GPIO.output(16,True)
#root.after(2000,checker)
elif label.image == blackPhoto:
label.image = colorPhoto
label.configure(image = colorPhoto
#GPIO.output(16,False)
#root.after(2000,checker)
elif not running:
label.image = colorPhoto
label.configure(image = colorPhoto)
#GPIO.output(16,False)
def press():
global running
if not running:
running = True
checker()
if running:
running = False
You miss a closing bracket at label.configure(image = colorPhoto
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to get the caret position in Python. I tried using win32gui.GetCaretPos() but it always returns 0,0.
Do you have any ideas how to make it work?
Thanks
Chris
If the caret is in a window created by another thread, you need to call AttachThreadInput. Assuming you want the caret of the foreground window, you can get to it like this:
import win32gui
import win32process
import win32api
fg_win = win32gui.GetForegroundWindow()
fg_thread, fg_process = win32process.GetWindowThreadProcessId(fg_win)
current_thread = win32api.GetCurrentThreadId()
win32process.AttachThreadInput(current_thread, fg_thread, True)
try:
print win32gui.GetCaretPos()
finally:
win32process.AttachThreadInput(current_thread, fg_thread, False) #detach