Python syntax error in seeming properly formatted code [closed] - python

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

Related

SyntaxError: invalid syntax (Python) [closed]

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 days ago.
Improve this question
I am experiencing the following error code:
elif event.type == pygame.KEYDOWN and not active:
^ SyntaxError: invalid syntax
This is my code:
active = False
for entry in self.textEntries:
if entry.clicked:
active = True
#Event loop. In-game control is routed through here
#Will probably need something more robust soon.
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.quit()
elif event.type == pygame.KEYDOWN and not active:
if event.key == pygame.K_SPACE:
self.paused = not self.paused
elif event.key == pygame.K_g:
#toggle draw grid
self.options['draw_grid'] = not self.options['draw_grid']
I checked if the code was indented properly, but I couldn't find any problems.

How to solve "Name error" in Python tkinter programme? [closed]

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

Can you tell me why i get the Error Message invalid syntax on my command [closed]

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)

Why isn't text showing in Tkinter? [closed]

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
I can't understand why the text isn't showing. I tried to reformat the program but it isn't showing the text.
import tkinter as tk
import random
Test = "test"
root = tk.Tk()
label = tk.Label(root, textvariable = Test, width = 30)
label.pack()
root.mainloop()
effbot is the recommend documentation for the tkinterlibrary.
The Label.textvariable attribute should point to a tkinter.StringVar() object:
>>> import tkinter as tk
>>> root = tk.Tk()
>>> test = StringVar()
>>> test.set('Hello')
>>> pinnarKvar = tk.Label(root, textvariable = test, width = 30)
>>> pinnarKvar.pack()
HereI am using IDLE so I don't use root.mainloop() since it dynamically updates.
To change what you see, after you call pinnarKvar.pack() call text.set() to update.

Raspberry Pi 2 Model B is preventing my def function [closed]

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("> "))

Categories

Resources