Related Content
Reading User Files With Tkinter In Python
The Tkinter library in Python has a number of file dialogs that allow programs to ask for a file from a user. Using these dialogs it is possible to accept a file from a user and read the contents of that file.
A Look At Running Python In A Web Browser With PyScript
PyScript is a framework that allows browsers to run Python code using HTML and the power of Pyodide and WebAssembly. This means that the Python runtime runs natively and can make full use of any Python code or package available.
Drawing Hitomezashi Stitch Patterns With Tkinter Canvas In Python
Inspired by a YouTube video I saw on awesome Numberphile channel about how to draw hitomezashi stitch patterns I decided to recreate them in Python with the aid of the Tkinter Canvas element.
Conway's Game Of Life With Tkinter In Python
Conway's game of life, was devised by John Conway in 1970 and is a way of modelling very simple cell population dynamics. The game takes place on a two dimensional board containing a grid of orthogonal cells. The game is technically a zero player game in that the initial setup of the game dictates the eventual evolution of the board.
Using Events With Tkinter Canvas Elements In Python
There are lots of ways to draw objects using the Tkinter Canvas element, but making the canvas elements interactable adds a lot to the applications you create. There are a few things to take into account when binding events like what events to trigger on and how to find out what item triggered what event.
Creating A Simple Calculator Application With Tkinter In Python
A calculator is a great application to create when learning how to code as it contains many of the things that most GUI applications will have, including behind the scenes processing of results.
Comments
Submitted by Anonymous on Tue, 03/01/2016 - 08:10
PermalinkSubmitted by Anonymous on Mon, 03/13/2017 - 19:59
PermalinkI am writing a drawing program for school but need to add the stop() function but can't figure out how to define and use it.
Submitted by Josiah on Fri, 10/13/2017 - 16:05
PermalinkAbove given syntax are useful.but i have an error
Submitted by priyanka on Mon, 03/19/2018 - 06:06
PermalinkSubmitted by Ash on Mon, 04/23/2018 - 16:43
PermalinkI am trying to make a chode your ending game but when they die it continues with the game. How do I make specific parts of my game stop when the player chooses a action and they die?
example
river = raw_input(“oh no there is a river what do we do?”)
print “you decide”
print(“1.go through the river”)
print(“1.swing on a vine over the river”)
answer = input()
if (answer==1):
print “you safely made it across”
if (answer==2):
print “you died when the vine broke”
how do I break answer 2 without stopping answer 1?
Submitted by Zylina Sala on Tue, 07/17/2018 - 22:15
PermalinkZylina Sala
import sys
if (answer == 2):
print("You died when the vine broke")
sys.exit()
Submitted by Ezekiel Koenig on Wed, 10/17/2018 - 19:58
Permalinki'm trying to get it to 'spit it out' when i say
sys.exit("[Error]THIS HAS NOT BEEN PROGRAMMED!")
but it just exits and doesn't say that...
please reply
P.S. Ignore the website. i didn't know what to put.
Submitted by edward green on Tue, 02/19/2019 - 17:52
PermalinkReading the python docs, you might be intercepting the exception that sys.exit() raises, which is then suppressing the error. Maybe?
Also, you don't have to put a website in, it's purely optional.
Submitted by giHlZp8M8D on Tue, 02/19/2019 - 21:03
Permalinkprint ("Guess any number between 1 and 20. You have 5 lives.")
from random import *
Memory = randint(1,20)
for i in range(5):
Guess = int(input("What is your guess?"))
if Guess == Memory:
print ("Correct!")
print ("You win!")
break
else:
print ("Not quite.")
print ("Oops! You ran out of lives!")
^This is what I'm being taught to make (a guessing game). If the player's guess was correct, it will come up with:
Correct!
You win!
Oops! You ran out of lives!
??? How to I get the game to stop before printing "Oops! You ran out of lives!"? Can anyone help?
Submitted by eva on Wed, 03/20/2019 - 21:31
PermalinkI just read about stopping a running program from within the program using: import sys; sys.exit('program stopping')
Very cool. When I tried this in Python 3.7 without the sys. in front of the exit, I got a window pop up asking if I really wanted to 'kill' or cancel. What's up with that?
Thanks!
Submitted by Treehugger Dave on Thu, 10/10/2019 - 12:40
PermalinkThank you!
Submitted by Anonymous on Tue, 05/26/2020 - 16:49
Permalinkelse:
print ("Not quite.")
print ("Oops! You ran out of lives!")
Fix it to:
else:
print ("Not quite.")
print ("Oops! You ran out of lives!")
Submitted by Anonymous on Wed, 06/10/2020 - 09:29
PermalinkHey, Im tyring to do a simailr project, but no matter what i do, nothing can stop my code. Can someone help me?
Submitted by Potato_P.J. on Mon, 10/12/2020 - 20:55
PermalinkHi, I'm trying to make a basic calculator. I want the person to close the thing when you want but i can't make it work. I can put the code in the comment and someone maybe would like to help me. It would be super helpful if someone helped me just to turn it of. I hope somebody reads this and helps me. I am using Microsoft Visual studio 2019 and i don't know if there is another way to make the code stop there or if you can use the same code in difrent compilars.
And I hope someone can understand me cause I'm not from a english speaking contury.
Here is my code:
print("The Calculator")
a = input("Enter A Number:")
b = input("Enter A Number:")
add = float(a) + float(b)
sub = float(a) - float(b)
multi = float(a) * float(b)
div = float(a) / float(b)
import sys
if input("Add, Subtract, Multiply or Divide:") == "Add":
print(a + "+" + b + "=")
print(add)
if input("Close Or Continue:") == "Close":
print("ByeBye, I Hope It Helped")
exit()
print("Hello")
else:
print("Here Comes The Next One")
if input("Add, Subtract, Multiply or Divide:") == "Subtract":
print(a + "-" + b + "=")
print(sub)
if input("Close Or Continue:") == "Close":
print("ByeBye, I Hope It Helped")
print(exit())
else:
print("Here Comes The Next One")
if input("Add, Subtract, Multiply or Divide:") == "Multiply":
print(a + "*" + b + "=")
print(multi)
if input("Close Or Continue:") == "Close":
print("ByeBye, I Hope It Helped")
print(exit())
else:
print("Here Comes The Next One")
if input("Add, Subtract, Multiply, Divide:") == "Divide":
print(a + "/" + b + "=")
print(div)
if input("Close Or Continue:") == "Close":
print("ByeBye, I Hope It Helped")
print(exit())
else:
print("Here Comes The Next One")
Submitted by LingLing on Sat, 01/30/2021 - 18:31
PermalinkHi LingLing,
I rewrote your calculator a little. Let me know what you think.
Submitted by giHlZp8M8D on Sat, 01/30/2021 - 20:09
Permalinki am trying to make an adventure game but every time you die you just continue with the game. PLZ HELP. PS - sys.exit() doesn't work :(... PSSSSSS - I am using repl.it / repl.com python.... whatever dey changed it tooooo. PSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS - I am pisseddddd.... Plz help.....
Submitted by mo on Thu, 03/18/2021 - 19:45
PermalinkHi Mo,
I think my comment form has eaten some of your code. Pop it in pastebin or something and I'll take a look :)
However, you'll probably want to look at my previous comment above that shows how to do this sort of thing using a loop. Might be worth looking into?
Submitted by giHlZp8M8D on Fri, 03/19/2021 - 10:47
PermalinkAny way to stop the code without completely killing CMD?
Submitted by Anonymous on Fri, 03/19/2021 - 14:22
PermalinkYou mean by pressing control+c?
Submitted by giHlZp8M8D on Fri, 03/19/2021 - 15:01
Permalinknice one, that of the adventurer!
Submitted by estrywetrrquewrvt on Thu, 07/15/2021 - 17:16
PermalinkAdd new comment