1
我想使用bash命令打印文件屬性並在Textview中寫入結果。 這裏通過選擇按鈕選擇路徑。文件路徑存儲在文本中。 os.system(「stat」+ text +「」)在終端上打印。我想存儲此命令的結果。在Gtk Textview中打印bash命令結果
#/usr/bin/python
import pygtk,gtk,os
class project:
def enter_callback(self,widget,entry):
entry_text=entry.get_text()
print("entry contents: %s \n" % entry_text)
def file_ok_sel(self,w):
print("%s " % self.filew.get_filename())
text=self.filew.get_filename()
print(text)
os.system("stat " + text + "")
def button1_select(self,widget,data=None):
self.filew=gtk.FileSelection("File selection")
self.filew.connect("destroy",self.destroy)
self.filew.ok_button.connect("clicked",self.file_ok_sel)
self.filew.cancel_button.connect("clicked",lambda w:self.filew.destroy())
self.filew.set_filename("penguin.png")
self.filew.show()
def destroy(self,widget):
print("quit")
def __init__(self):
self.window=gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("printing")
self.window.connect("delete_event",lambda a1,a2:gtk.main_quit())
self.window.set_border_width(20)
vbox=gtk.VBox(True,2)
self.window.add(vbox)
label=gtk.Label("Select File")
label.set_alignment(0,0)
vbox.pack_start(label,False,False,0)
label.show()
#adding TEXTVIEW to print bash command result
textview = gtk.TextView()
textbuffer = textview.get_buffer()
self.window.add(textview)
vbox.pack_start(textview,True,True,0)
textview.show()
vbox.show()
self.window.show()
#Button used to select FILE
button=gtk.Button("select")
button.connect("clicked",self.button1_select,"select 1")
vbox.pack_start(button,True,True,2)
button.show()
def main():
gtk.main()
return 0
if __name__=="__main__":
project()
main()
我想使用該結果在TextViev小部件。我該怎麼做? – 2014-10-19 22:13:33
更新textview的緩衝區 – Parker 2014-10-19 22:20:08
但我如何更新。 – 2014-10-19 22:36:38