user interface - Put a label beside a text entry in python gtk -
so i'm trying build pretty basic gui using python gtk, i'm getting frustrated quickly. how put label beside text entry? how can make entry smaller? button smaller? i'm going have add more entries , take them in @ once process information, , don't need them fill window... thanks.
#!/usr/bin/python #-*- coding: iso-8859-1 -* import pygtk pygtk.require('2.0') import gtk class text_box: #callback function, data arguments ignored def hello(self, widget, entry): entry_text = self.entry.get_text() print("entry contents: ".format(entry_text)) def delete_event(self, widget, event, data=none): #return of false deletes event, true keeps print("delete occurred") return false def submit(self, button): try: input = self.entry.get_text() print(float(input)) return input except valueerror: print("this not number...") self.md = gtk.messagedialog(none, gtk.dialog_destroy_with_parent, gtk.message_error, gtk.buttons_close, "this not number") self.md.set_position(gtk.win_pos_center) self.md.run() self.md.destroy() def enter(self, button): try: input = self.entry.get_text() input = float(input) print(input) return input except valueerror: self.md = gtk.messagedialog(none, gtk.dialog_destroy_with_parent, gtk.message_error, gtk.buttons_close, "this not number") self.md.run() self.md.destroy() print("this not number...") #another callback def destroy(self, widget, data=none): gtk.main_quit() def __init__(self): self.fix = gtk.fixed() #create new window self.window = gtk.window(gtk.window_toplevel) self.window.set_size_request(500, 500) self.window.set_title("powder application") self.window.set_position(gtk.win_pos_center) vbox = gtk.vbox(false,0) self.window.add(vbox) vbox.show() #when window given delete_event, close self.window.connect("delete_event", self.delete_event) #connect "destroy" event signal handler #occurs gtk_widget_destroy() or false in delete_event self.window.connect("destroy", self.destroy) #sets border width of window self.window.set_border_width(10) #creates button self.button = gtk.button("submit") #self.button.connect("clicked", self.hello, none) #submit data in window on click self.button.connect_object("clicked", self.submit, self.window) #make entry box self.entry = gtk.entry() self.label = gtk.label("powder density") vbox.pack_start(self.label, false, false, 0) self.label.show() self.entry.set_max_length(20) self.entry.select_region(0, len(self.entry.get_text())) #self.entry.connect("activate", self.hello, self.entry) self.entry.connect_object("activate", self.enter, self.window) vbox.pack_start(self.entry, false, false, 0) self.entry.show() #this packs button , entry window #self.window.add(self.button) #self.window.add(self.entry) #hbox = gtk.hbox(false, 0) #vbox.add(hbox) #hbox.show() #the final step display newly created widget. vbox.pack_start(self.button, false, false, 00) self.button.show() #and window self.window.show() def main(self): #all pygtk apps must have gtk.main(). control ends here #and waits event occur gtk.main() return 0 #if program run, create gui instance , show if __name__ == "__main__": hello = text_box() hello.main()
try using table , add table window using:
table=gtk.table(1,4,true) table.attach(label,0,1,0,1) table.attach(entry,1,3,0,1) table.attach(button,3,4,0,1) window.add(table) window.show_all()
this displays label beside text box, button beside it
Comments
Post a Comment