嘿我正在尝试创建一个基于GUI的应用程序,可用于枚举pcap文件,所需的功能就是当用户点击枚举时,另一个窗口出现,用户可以输入应该运行的文件名
仅仅是为了测试我目前正在使用原始bash命令输入,但不幸的是,这对我不起作用。
以下是我的代码: -
from tkinter import *
import tkinter
import subprocess
window = tkinter.Tk()
window.minsize(300,300)
#back = tkinter.Tk()
window.title("Extractor")
e1 = Entry(window)
def disp():
subprocess.call([e1.get()])
def callback():
Label(window,text="Command").grid(row=0)
e1 = Entry(window)
e1.insert(10,"Please input")
e1.grid(row=0,column=1)
process = tkinter.Button(window,text="GO",command=disp)
process.grid(row=10,column=5)
toplabel=tkinter.Label(window,text="Enumeration tool for PCAP")
enum = tkinter.Button(window,text ="Enumerate",command=callback)
enum.grid(row=10)
window.mainloop()
产生错误: -
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1544, in __call__
return self.func(*args)
File "GUI.py", line 11, in disp
subprocess.call([e1.get()])
File "/usr/lib/python2.7/subprocess.py", line 172, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 394, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1047, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
我需要帮助调用另一个窗口框架中的另一个窗口,然后如何放置一些命令,如bash <input>
,这样bash总是被隐藏,只有输入执行脚本&amp;我该如何解决这个错误。
答案 0 :(得分:1)
您的代码只需很少的更改即可使用:
...
window.title("Extractor")
e1 = None # <- your were creating two instances of your entry, one in
# global namespace and other local to the functions. Why?
def disp():
subprocess.call([e1.get()]) # no need for for global, its a read op
def callback():
global e1 # refer to global e1 on writes
Label(window,text="Command").grid(row=0)
e1 = Entry(window)
...
您可以创建除Tk()
根窗口之外的其他窗口,调用tkinter.Toplevel(root)
来实例化新的根子窗口。