Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get cmd in Tkinter widget

I'm creating Tkinter GUI and want to add windows CMD into tkinter widget. I would like to use console to connect to database. I did some research and found only pyconsole module, but with some bugs:

  • cls is not going to do what you expect;
  • edit is not going to show an editor (try start edit instead);
  • prompt anything fails too;
  • the color command is not implemented;
  • the great ^C isn't supported too (it actually copies text, instead of interrupting a process).

Especially ^C command ommited is huge limitation for sql scripts i want to run.

I'm able to open console like this:

Popen(["cmd.exe"], creationflags=CREATE_NEW_CONSOLE)

But with this approach I don't know how to interact with the GUI (is it even possible?)

Also my Text widget can read output from command line, but I need to also write in that command line, not just read it...

Is there a possibility to get regular CMD into Tkinter widget, which will react with the rest of widgets in GUI?

Desired behaviour would be CMD console on the right side as you can see on picture below (in tkinter window), that would interact with the Listbox on the left. I'm not looking for exact code (that's why no my code stated here), but method/solution how to put CMD into tkinter.

Photo: enter image description hereenter image description here

Thanks

Honza

like image 281
zajcev Avatar asked May 15 '15 10:05

zajcev


People also ask

How do I run a Tkinter in CMD?

Tkinter can be installed using pip. The following command is run in the command prompt to install Tkinter. This command will start downloading and installing packages related to the Tkinter library. Once done, the message of successful installation will be displayed.

What is command in button Tkinter?

Tkinter Button command option sets the function or method to be called when the button is clicked. To set a function for execution on button click, define a Python function, and assign this function name to the command option of Button.

How do I get entries in Tkinter?

An Entry widget in Tkinter is nothing but an input widget that accepts single-line user input in a text field. To return the data entered in an Entry widget, we have to use the get() method. It returns the data of the entry widget which further can be printed on the console.

Is Tk () a widget?

Tk is a package that provides a rich set of graphical components for creating graphical applications with Tcl. Tk provides a range of widgets ranging from basic GUI widgets like buttons and menus to data display widgets. The widgets are very configurable as they have default configurations making them easy to use.


1 Answers

I think you can use an Entry to input the commands you want to execute. Then you can use subprocess.run and subprocess.Popen to execute the commands, and a Text or even better a tkinter.scrolledtext.ScrolledText widget to show the results.

like image 168
gms Avatar answered Sep 27 '22 22:09

gms