简体   繁体   English

如何从其他脚本访问GUI脚本中的gtk.Entry()? 蟒蛇

[英]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.

相关问题 在python中,如何从Gtk.entry输入框中获取值并将其传递给变量? - In python, how can I get a value from a Gtk.entry entry box and pass it to a variable? 如何阻止gtk.Entry失去对arrow buttonpress的关注? - How do I stop gtk.Entry from losing focus on arrow keypress? 如何从持续运行脚本的另一台 PC 访问数据? - How can I access data from my other PC that is continuously running a script? 我可以导入 python 脚本以使其在我的 GUI 中运行吗? - Can I import a python script to make it run in my GUI? Python Gtk.Entry占位符文本 - Python Gtk.Entry placeholder text 如何从 Gtk.Entry() 存储为变量,然后例如 *10 并将新值放入 Gtk.Label() 中,在 python3 中使用 PyGObject?(PyGtk) - How to store from a Gtk.Entry() as a variable, and then for example *10 and put the new value in a Gtk.Label() , in python3 using PyGObject?(PyGtk) python gtk.entry()图标connect:有可能吗? - python gtk.entry() icon connect: is it possible? 如何格式化Gtk.Entry中的条目 - How to format the entries in Gtk.Entry 如何执行我的脚本并在 PYQT5 的 GUI 中打印它? - How can I execute my script and print it in the GUI in PYQT5? Tkinter GUI处于活动状态时如何运行python脚本? - How can I run my python script while a Tkinter GUI is active?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM