dimanche 27 octobre 2019

how to fix No display name and $DISPLAY environment variable python error

I am trying to make a game about clicking a button to get sap(long story), you click a tkinter button, but when i tried to add it to flask but it kept saying "

Traceback (most recent call last):
  File "/home/4TRS/mysite/SAPGAME.py", line 2, in <module>
    window = tkinter.Tk()
  File "/usr/lib/python3.7/tkinter/__init__.py", line 2020, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable"

This is my code

import tkinter
window = tkinter.Tk()
button=tkinter.Button(window, text="Click to get sap", width=40)
button.pack(padx=10, pady=10)
clickcount = 0
def onclick(event):
    global clickcount
    clickcount = clickcount + 1
    sap1 = clickcount
    sap = str(sap1)
    if clickcount >= 1:
        button.configure(text="You have " + sap + " saps")
button.bind("<ButtonRelease-1>", onclick)
window.mainloop()

I want to be able to simply click the button. when I do it in IDLE it works just fine but when i try it on any online IDE it has the same error. I have been at this for hours and can't find a solution.




Aucun commentaire:

Enregistrer un commentaire