简体   繁体   中英

How to include a command line interface in a gui in python

I'm currently building an console application in python that does a lot of calculations on input gotten from the user and i've seen several apps that have gui windows but the input is still gotten from the console and this is exactly what i want, i'm currently learning tkinter so i wanted to ask is it possible to do this in tkinter because the tutorial i have on tkinter dosen't talk about including consoles in gui's here is a screenshot of what i mean https://www.imageupload.co.uk/image/ZEXe though in the screenshot the command line just prints out what is going on in the program but i want my main application to be in that area, so i can get input from the user and then the results can be printed out on the gui. Answers can also suggest other python gui frameworks. Thanks

Tkinter can accept text inputs and return values based on what is put in. As far as I know there is no actual command line input function. You could always try implementing it yourself. I think this is very customizable so I'm not going to write it myself but these are some of the things u might use:

textbox = Entry(root)
textbox.pack()
textbox.config(bg="red") #this would change the background to black. fg for text color
textarea = Text(root) #this creates a big text area
#textbox.get() will return the value of the textbook

Also, you could embed a full terminal into a tkinter window by using xterm (you might need to install it first if it's not natively available on your machine.

from tkinter import *

import os

root = Tk()
termf = Frame(root, height=500, width=500)

termf.pack(fill=BOTH, expand=YES)
wid = termf.winfo_id()
os.system('xterm -into %d -geometry 100x100 -sb &' % wid)

root.mainloop()

This creates a new tkinter window (500 x 500) and them embeds an xterm window into it (100 x 100)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM