简体   繁体   English

如何在python的gui中包含命令行界面

[英]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.我目前正在用 python 构建一个控制台应用程序,它对从用户获得的输入进行大量计算,我已经看到几个具有 gui 窗口的应用程序,但输入仍然是从控制台获得的,这正是我想要的,我目前正在学习 tkinter,所以我想问一下是否可以在 tkinter 中执行此操作,因为我在 tkinter 上的教程没有谈论在 gui 中包含控制台,这是我的意思的屏幕截图https://www.imageupload .co.uk/image/ZEXe虽然在截图中命令行只是打印出程序中发生的事情,但我希望我的主应用程序在那个区域,所以我可以从用户那里获得输入,然后结果可以打印在 gui 上。 Answers can also suggest other python gui frameworks.答案还可以建议其他 python gui 框架。 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. Tkinter 可以接受文本输入并根据输入的内容返回值。据我所知,没有实际的命令行输入功能。 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.此外,您可以使用xterm将一个完整的终端嵌入到tkinter窗口中(如果您的机器本身不可用,您可能需要先安装它。

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)这将创建一个新的tkinter窗口 (500 x 500) 并将xterm窗口嵌入其中 (100 x 100)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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