Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Input error
#1
I have only just started using tkinter today and I am getting an error which I cannot work out how to solve. I am making a slot machine and I want to add some GUI.
The error is:
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

The code is:
def show_entry_fields():
    print("Thanks for playing %s" % (e1.get()))
    n = e1.get()
    return n
      master = tk.Tk()
      tk.Label(master, text="Enter your name").grid(row=0)
      e1 = tk.Entry(master)
      e1.grid(row=0, column=1)

      tk.Button(master, text='Quit', command=master.quit).grid(row=3, column=0, sticky=tk.W, pady=4)
      tk.Button(master, text='Show', command=master.show_entry_fields).grid(row=3, column=1, sticky=tk.W, pady=4)
      tk.mainloop()

      name = show_entry_fields()
      text = ("{} {}".format(name, str(coins)))
Any help is greatly appreciated!
Reply
#2
I don't get your error, but I get an error when you do this:

command=master.show_entry_fields

master is your window. show_entry_fields is a function in your program. master.show_entry_fields is a method in master's class, but that method does not exist.

When asking a question about an error you need to provide the code that actually produces the error. I changed the command assignment to not include "master." and the code you provided runs without error. It doesn't do anything, but there is no error.

If you are still having problems try submitting enough code that we can reproduce the error. Also include the entire error text.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020