-2

I tried to create a simple GUI in Python which gets input from the user and execute a shell script based on the user input.

Since it has to call a Shell script, I'm trying to create a GUI in the Python 2.7.6, which is the only version available in Linux Env. I tried to use Tkinter, but its saying ImportError: No module named _tkinter

ImportError: No module named _tkinter

Any alternatives or suggestions would be helpful!

Vicky
  • 312
  • 2
  • 9
  • 19
  • Are you trying to import `_tkinter`? Because that's not the name of the module. Try importing `Tkinter` instead. – figbeam Feb 12 '19 at 07:27
  • Thanks for the response. I tried using Tkinter as well, but getting same import error..I think Tkinter is not supported in my Python 2.7.6 version, can u suggest any alternative modules which can be used for creating a simple UI.. – Vicky Feb 12 '19 at 07:34
  • Tkinter is native to all python versions. See https://docs.python.org/2/library/tkinter.html – Demi-Lune Feb 12 '19 at 08:02
  • Try `sudo apt-get install python-tk` if you're on a Debian(-derivate). Proberly a dublicate of [Install tkinter for Python](https://stackoverflow.com/questions/4783810/install-tkinter-for-python). – Aoki Ahishatsu Feb 12 '19 at 08:04
  • What do you mean by "Linux Env"? – Stop harming Monica Feb 12 '19 at 08:06
  • Its the Linux environment for which we dont have any access to install or upgrade.. But I have python 3.7 in Windows 10, if there's any way to call the shell script in Linux environment from Windows(Via Python script), please let me know.. Thanks for you time.. – Vicky Feb 12 '19 at 08:51
  • If the linux env supports SSH connection, you can try `paramiko` module. – acw1668 Feb 12 '19 at 10:38
  • tkinter is definitely supported in python 2.7.6. It seems like you have a broken installation. – Bryan Oakley Feb 12 '19 at 13:55
  • Oh, Maybe! :( is there any way to check broken installation? I'll try to check how to use `paramiko` module.. – Vicky Feb 12 '19 at 15:46
  • If the Linux env is 64-bit system, check whether `/usr/lib64/python2.7/lib-dynload/_tkinter.so` exists. – acw1668 Feb 13 '19 at 09:33
  • Python was installed without tkinter support. – Stop harming Monica Feb 18 '19 at 11:07
  • Next time, show a [complete](https://meta.stackoverflow.com/questions/359146) stack trace. – Karl Knechtel Apr 29 '23 at 01:30

1 Answers1

0

In python 2.7 the module is called Tkinter (capital T). and the most common usecase is:

from Tkinter import *
root = Tk()
root.mainloop()

If you are looking for a quick interface option that works on Linux (or any other Operating system) Then maybe look at python-Flask Flask.

This framework will allow you to take HTML, CSS, JS and PHP and transfer the data back to python. So you can build your entire GUI as a webpage, import it to flask, then use URLs to get user inputs back into python.

Scott Paterson
  • 392
  • 2
  • 17
  • Still not working :(, as Bryan said maybe it could be a broken one! Thanks for the suggesting the alternative(Flask), will try to create UI using that! :) – Vicky Feb 12 '19 at 15:48
  • 1
    just a Quick FYI, Flask is not a GUI. you create the GUI in HTML and CSS then use JS to send commands back to Flask (its a webserver). You will need a secondary application to actually view the HTML page (a webbrowser) i have one for python but its built using pyGTK so im not sure if it will work for you. – Scott Paterson Feb 12 '19 at 16:00
  • Other possible GUI frameworks are GTK, Kivy and PyQt. if you are not familiar with HTML or JS try take a look into them first. – Scott Paterson Feb 12 '19 at 16:01
  • Thanks a lot for the info! It really helps!:) – Vicky Feb 12 '19 at 17:21