0

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
  • 1
  • 4
  • 26
  • 35
madikh mughal
  • 43
  • 1
  • 4

2 Answers2

7

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
  • 15,040
  • 7
  • 22
  • 53
Kartheek
  • 156
  • 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
  • 28,850
  • 10
  • 94
  • 99
Ayat
  • 1