1

I'm working on TkInter on Repl.it and have run into a problem, this is my code:

from tkinter import *
import tkinter as tk

root = tk.Tk()
root.geometry('400x400')

I run into this error:

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

How do I solve this?

Eliahu Aaron
  • 4,103
  • 5
  • 27
  • 37
madikh mughal
  • 53
  • 1
  • 1
  • 5

2 Answers2

8

You're apparently trying to do this with repl.it's "Python", which doesn't support the display that tkinter needs. They do offer a separate "Tkinter" option, although it's quite far down the list of languages. Here's a shortcut: https://repl.it/languages/tkinter

There you don't get that error. In order to actually get the window shown, you'll have to also add this under your current code:

root.mainloop()

Demo

Kelly Bundy
  • 23,480
  • 7
  • 29
  • 65
Kartheek
  • 164
  • 2
  • 17
0
from tkinter import *  
  
top = Tk()  
  
top.geometry("400x250")  
  
#creating label  
uname = Label(top, text = "Username").place(x = 30,y = 50)  
  
#creating label  
password = Label(top, text = "Password").place(x = 30, y = 90)  
  
  
sbmitbtn = Button(top, text = "Submit",activebackground = "pink", activeforeground = "blue").place(x = 30, y = 120)  
  
e1 = Entry(top,width = 20).place(x = 100, y = 50)  
  
  
e2 = Entry(top, width = 20).place(x = 100, y = 90)  
  
  
top.mainloop()  
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Ayat
  • 1
  • In Tinter and Python it's generally a bad practice to initiate an object and modify it with methods because the majority of those methods return None. The widget will still be initialised, however you won't be able to use it with its name. To preserve control, separate initialisation and modification. – Владислав Король Oct 26 '22 at 13:54