How do I define root for tkinter in Python 3? I'm using an online Python editor

Still Here Coding

I am trying to make a label, but I can't define the root variable! Please help me!

Update: I am using an online Python editor called repl.it

I am using Python 3.0

This is my code:

import time
from tkinter import *

root = Tk()

def w(t):
  if t == t:
    time.sleep(t)
print("In the following story, you are a mouse. Please fill out the following information (the story will use this name and gender).")
w(2)
print('\n')

while(True):
  name = input("Your Name:")
  if name.isalpha():
    break
  elif name != str:
    print('\n')
    print("Error! Please enter a name!")
    print('\n')

w(0.5)
print('\n')

while(True):
  gender = input("Your Gender (Male / Female):").lower()
  if gender == "male":
    heorshe = "he"
    hisher = "his"
    himher = "him"
    himselfherself = "himself"
    HeShe = "He"
    break
  elif gender == "female":
    heorshe = "she"
    hisher = "her"
    himher = "her"
    himselfherself = "herself"
    HeShe = "He"
    break
  else:
    print('\n')
    print("Error Please enter a valid gender!")
    print('\n')

w(0.5)
print('\n')
input("Press Enter to Begin The Story")
w(0.5)
print('\n')
print("The Lion and The Mouse")
print("A Short Tale by Aesop")
w(1)
print('\n')
print("Once upon a time in a secluded jungle, there was a mouse.")
w(1.25)
print('\n')
print("%s was a very curious little mouse. Whenever %s saw something that caught %s eye, %s would always go and investigate." % (name, heorshe, hisher, heorshe))
w(2.5)
print('\n')
print("One day, %s came across a mighty lion. At first the lion didn't see %s, but due to %s curiosity, %s revealed %s. The lion had spotted %s." % (heorshe, himher, hisher, heorshe, himselfherself, himher))
w(3.25)
print('\n')
print("Hungry for a meal, the lion lunged at the mouse.")
print('\n')
w(1.75)
print("With the mouse in the lion's grip, the lion licked his lips, ready to bite in.")
print('\n')
w(1.5)
while(True):
  mercyoryell = input("Do you 'ASK FOR MERCY' or 'YELL HELP'?").lower()
  if mercyoryell == "ask for mercy":
    print('\n')
    print("Mouse: Oh please, great lion, let me go free! I promise I can repay you later!")
    w(1)
    print('\n')
    print("Lion: Ha! The thought of a mere mouse repaying me? I shall let you go, but only because you have given me such a great laugh!")
    w(.75)
    print('\n')
    print("The lion let the mouse go, and the mouse scurried away as fast as %s could." % (heorshe))
    print('\n')
    break
  elif mercyoryell == "yell help":
    print('\n')
    print("Mouse: HELLLLPPPP! I AM GOING TO GET EATEN BY A NASTY LION! SOMEBODY HELP ME! ANYBODY! AHHHH!!!")
    w(1.35)
    print('\n')
    print("Alas, the mouse's attempts were not successful. The lion quickly gobbled %s up." % (himher))
    w(1.5)
    print('\n')
    label = Label(root, text="The End!", bg="white", fg="black", font=("Comic Sans MS", 35, "bold"), height=75, width=75)
    print(label)
  else:
    print('\n')
    print("Error. Please type either ASK FOR MERCY or YELL HELP.")
    print('\n')
  w(1)
  print("A couple of days later, the mouse explores the forest again. %s comes across the lion, all bundled up in rope, moaning in pain." % (HeShe))
  print('\n')
  w(1.5)
  print("Mouse: What happened? How did you get caught in this net?")
  print('\n')
  w(1)
  print("Lion: The stupid hunters set up a net right outside of my den! Thats how! Now hurry up and get me out of here before they come back, you stupid mouse!")
  w(1.75)
  print('\n')
  while(True):
    lastscene = input("Do you 'HELP HIM OUT' or 'IGNORE HIM'?").lower()
    if lastscene == "help him out":
      w(.5)
      print('\n')
      print("The mouse starts chewing on the rope. %s finally makes a hole big enough for the lion to escape from, and the lion jumps out of the net")
      w(1.5)
      print('\n')
      break
    elif lastscene == "ignore him":
      w(.5)
      print('\n')
      print("Mouse: Why would I help you when you show me no kindness? I'll leave you to the hunters, stupid lion!")
      w(.75)
      print('\n')
      print("The mouse runs away from the lion, ignoring him.")
      print('\n')
      w(1.5)
      print("Later on that day, a deafening growl is heard. The lion had been found by the hunters, and was killed.")
      w(1.5)
      print('\n')
      label = Label(root, text="The End!", bg="white", fg="black", font=("Comic Sans MS", 35, "bold"), height=75, width=75)
      print(label)
    else:
      w(.5)
      print('\n')
      print("Error! Please enter either HELP HIM OUT or IGNORE HIM !")
      print('\n')
w(.5)
print("Lion: Thank you so much, kind mouse! I saved you, and you did indeed repay me! I will now forever show my gratitude towards you, my humble friend!")
w(1.5)
print('\n')
print("No act of kindness, no matter how small, is ever wasted.      -Aesop")
print('\n')
w(1.5)
label = Label(root, text="The End!", bg="white", fg="black", font=("Comic Sans MS", 35, "bold"), height=75, width=75)
print(label)

And finally, this is the error message I get when I run the code:

    Traceback (most recent call last):
  File "python", line 4, in <module>
_tkinter.TclError: no display name and no $DISPLAY environment variable

I have no idea what to do, and none of the several guides I've looked up have helped me.

Bryan Oakley

In a comment you wrote:

I'm using an online editor for python as i do not have it downloaded.

You can't run tkinter via a web server. There is simply nothing you can do to make that work.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I list root DN's using python ldap?

From Dev

How do I stop a timer in Python (tkinter)?

From Dev

How do i refresh the label in python with Tkinter

From Dev

How do I save an image in python 3 using PIL?

From Dev

How do I force a redraw using python in gtk3?

From Dev

How do I send desktop notifications using Python 3?

From Dev

How do I check a checkbox using selenium in Python3

From Dev

How do I force a redraw using python in gtk3?

From Dev

How do I set IDLE as the default editor for Python scripts?

From Dev

How do I change the default editor for a python file?

From Dev

How do I set IDLE as the default editor for Python scripts?

From Dev

How can I create a new Graph Editor in Maya using Python?

From Dev

How do I define custom comparison (0 < mytype) in python?

From Dev

How do I define a datetime field in a python dataclass?

From Dev

How do I define the split_train_test in Python?

From Dev

How do I define custom comparison (0 < mytype) in python?

From Dev

How do I install tkinter on Ubuntu for two separate versions of Python 3?

From Dev

How do I delete from a SQLite database in python using a tkinter entry instead of stating a string or value?

From Dev

How do I show different groups of radio buttons at different times in python using Tkinter?

From Dev

Python:Tkinter -- How do I get cursor to show busy status

From Dev

how do i display search results in Python Tkinter window

From Dev

How do I link python tkinter widgets created in a for loop?

From Dev

How do I access a dictionary database in Python Tkinter for usernames and passwords?

From Dev

How do I pass a variable between two functions in tkinter python?

From Dev

How do I correct this function to create a label in Tkinter Python?

From Dev

How do I use Python Tkinter with sending mail?

From Dev

How do I set up Tkinter in python to display and update a variable?

From Dev

Python: How do I detect visible shape detection in Tkinter

From Dev

How can I take the square root of -1 using python?

Related Related

  1. 1

    How do I list root DN's using python ldap?

  2. 2

    How do I stop a timer in Python (tkinter)?

  3. 3

    How do i refresh the label in python with Tkinter

  4. 4

    How do I save an image in python 3 using PIL?

  5. 5

    How do I force a redraw using python in gtk3?

  6. 6

    How do I send desktop notifications using Python 3?

  7. 7

    How do I check a checkbox using selenium in Python3

  8. 8

    How do I force a redraw using python in gtk3?

  9. 9

    How do I set IDLE as the default editor for Python scripts?

  10. 10

    How do I change the default editor for a python file?

  11. 11

    How do I set IDLE as the default editor for Python scripts?

  12. 12

    How can I create a new Graph Editor in Maya using Python?

  13. 13

    How do I define custom comparison (0 < mytype) in python?

  14. 14

    How do I define a datetime field in a python dataclass?

  15. 15

    How do I define the split_train_test in Python?

  16. 16

    How do I define custom comparison (0 < mytype) in python?

  17. 17

    How do I install tkinter on Ubuntu for two separate versions of Python 3?

  18. 18

    How do I delete from a SQLite database in python using a tkinter entry instead of stating a string or value?

  19. 19

    How do I show different groups of radio buttons at different times in python using Tkinter?

  20. 20

    Python:Tkinter -- How do I get cursor to show busy status

  21. 21

    how do i display search results in Python Tkinter window

  22. 22

    How do I link python tkinter widgets created in a for loop?

  23. 23

    How do I access a dictionary database in Python Tkinter for usernames and passwords?

  24. 24

    How do I pass a variable between two functions in tkinter python?

  25. 25

    How do I correct this function to create a label in Tkinter Python?

  26. 26

    How do I use Python Tkinter with sending mail?

  27. 27

    How do I set up Tkinter in python to display and update a variable?

  28. 28

    Python: How do I detect visible shape detection in Tkinter

  29. 29

    How can I take the square root of -1 using python?

HotTag

Archive