Question

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()

The problem is that I dont know how to use that function/command outside of #1 script

Lets say #1 script is called test.py and inside there is:

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:

Meta = self.client.get_file_and_metadata(#here it needs to go self.Textbox.get_text())
Was it helpful?

Solution

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:

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

i changed it to

Meta = self.client.get_file_and_metadata(getpass.getuser())

and finally the string from self.Textbox i got through uploading

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 :))

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top