嘿我试图让这个工作,因为,一旦GUI加载我想要一个文件输入,并说我将它存储在“X”,这也是一个函数内,现在我想访问此文件值另一个python脚本
我尝试了inhempiance,导入函数,脚本,对象。
这是驱动程序代码: -
from tkinter import *
import tkinter
import subprocess
global x
x=""
global e1
e1=""
window = tkinter.Tk()
class Driver:
window.minsize(300,300)
window.title("Extractor")
e1 = None
global showx
def showx():
x=e1.get()
print x
# def __init__(self):
# self.x = x
global callback
def callback():
global e1
Label(window,text="File").pack()
e1 = Entry(window)
e1.insert(10,"Please input")
e1.pack()
process = tkinter.Button(window,text="GO",command=showx)
process.pack()
toplabel=tkinter.Label(window,text="Enumeration tool for PCAP")
enum = tkinter.Button(window,text ="Enumerate",command=callback)
enum.pack(side=TOP)
def quit():
window.destroy()
quit=Button(window,text="Exit",command=quit)
quit.pack(side=BOTTOM)
window.mainloop()
我的尝试:
root@karma:~/Desktop/IITK/Filter/GUI?# python
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import GUI as obj
>>> obj.showx()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "GUI.py", line 13, in showx
x=e1.get()
NameError: global name 'e1' is not defined
>>> obj.x()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'x'
>>> obj.showx()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "GUI.py", line 13, in showx
NameError: global name 'e1' is not defined
>>>
root@karma:~/Desktop/IITK/Filter/GUI?#
root@karma:~/Desktop/IITK/Filter/GUI?# python
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import GUI as obj
>>> obj.showx()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "GUI.py", line 14, in showx
x=e1.get()
NameError: global name 'e1' is not defined
>>> NameError: global name 'disp' is not defined
File "<stdin>", line 1
NameError: global name 'disp' is not defined
^
SyntaxError: invalid syntax
>>>
root@karma:~/Desktop/IITK/Filter/GUI?# python
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import GUI as obj
>>> obj.showx()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "GUI.py", line 16, in showx
x=e1.get()
AttributeError: 'str' object has no attribute 'get'
>>>
>>> obj.x()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable
>>>