[英]How can i access gtk.Entry() in my GUI script from my other script? Python
I have #1 .py script which is a GTK GUI application and I have a second script which needs a string from the first script that can be gained by gtk.Entry().get_text()
我有#1 .py脚本,它是GTK GUI应用程序,还有第二个脚本,它需要第一个脚本中的字符串,可以通过
gtk.Entry().get_text()
获得该字符串
The problem is that I dont know how to use that function/command outside of #1 script 问题是我不知道如何在#1脚本之外使用该功能/命令
Lets say #1 script is called test.py and inside there is: 假设#1脚本称为test.py,里面有:
def __init__(self):
#some code
#some code
self.TextBox = gtk.Entry()
self.TextBox .connect("key-press-event", self.keyEnter)
#some code
#some code
#some code
def keyEnter(self, widget, ev):
if ev.keyval == 65293 and not self.TextBox.get_text() == "":
self.TextBox1.grab_focus()
self.TextBox.set_editable(False)`
And #2 script is called test2.py and inside contains: #2脚本称为test2.py,其中包含:
Meta = self.client.get_file_and_metadata(#here it needs to go self.Textbox.get_text())
I couldn't access the gtk.Entry()
from other script I wrote since it is run as a separate process (i don't have that knowledge to manipulate processes yet) i did this: 我无法从我编写的其他脚本中访问
gtk.Entry()
,因为它是作为一个单独的进程运行的(我尚不具备操作进程的知识),我这样做是:
def keyEnter(self, widget, ev):
if ev.keyval == 65293 and not self.TextBox.get_text() == "":
self.TextBox1.grab_focus()
self.TextBox.set_editable(False)
file = open('file.txt', 'w+')
file.write(self.TextBox.get_text())
file.close()
i changed 我变了
Meta = self.client.get_file_and_metadata(#here it needs to go self.Textbox.get_text())
that was supposed to download the file with the name written in self.Textbox
可以下载使用
self.Textbox
编写的名称的文件
i changed it to 我将其更改为
Meta = self.client.get_file_and_metadata(getpass.getuser())
and finally the string from self.Textbox
i got through uploading 最后是来自
self.Textbox
的字符串,我通过上传获得了
with open("file.txt", "r") as chat:
data=chat.read().splitlines(True) #split lines in the list
d = str(data[:1]) #take only first line from the list
dat=str(d).strip("[]") #remove the brackets "[]" that remained when string was extracted from the list
with open("file.txt", "w") as chat1:
chat1.writelines(data[1:]) # writes all except the first line
chat.close()
chat1.close()
self.f = open('file.txt', 'rb')
self.response = self.client.put_file(str(dat[:-2]), self.f) #str(dat[:-2]) -> i wanted to remove the newline char "\n"
I dont know if anyone will find this helpful but this solved the problem at my side :)) 我不知道是否有人会觉得这有帮助,但这在我这方面解决了问题:))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.