簡體   English   中英

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

[英]How to include a command line interface in a gui in python

我目前正在用 python 構建一個控制台應用程序,它對從用戶獲得的輸入進行大量計算,我已經看到幾個具有 gui 窗口的應用程序,但輸入仍然是從控制台獲得的,這正是我想要的,我目前正在學習 tkinter,所以我想問一下是否可以在 tkinter 中執行此操作,因為我在 tkinter 上的教程沒有談論在 gui 中包含控制台,這是我的意思的屏幕截圖https://www.imageupload .co.uk/image/ZEXe雖然在截圖中命令行只是打印出程序中發生的事情,但我希望我的主應用程序在那個區域,所以我可以從用戶那里獲得輸入,然后結果可以打印在 gui 上。 答案還可以建議其他 python gui 框架。 謝謝

Tkinter 可以接受文本輸入並根據輸入的內容返回值。據我所知,沒有實際的命令行輸入功能。 你總是可以嘗試自己實現它。 我認為這是非常可定制的,所以我不會自己編寫它,但這些是您可能會使用的一些東西:

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

此外,您可以使用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()

這將創建一個新的tkinter窗口 (500 x 500) 並將xterm窗口嵌入其中 (100 x 100)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM