python - How can a program that uses GUI be constructed? -


i have started python, 2 weeks ago. now, trying create guis pygobject using glade.

however, puzzled on how general layout of program should be.

should use class main program , signals or should separate them?

is there "best approach" this?

or in below humble approach of mine, should not use classes @ all?

how communicate between functions in below example? example, how set parent parameter of gtk.messagedialog function main window of program?

python code:

#!/usr/bin/python  try:     gi.repository import gtk except:     print('cannot import gtk')     sys.exit(1)  # confirm , exit when quit button clicked. def on_button_quit_clicked(widget):     confirmation_dialog = gtk.messagedialog(parent = none,                                             flags = gtk.dialogflags.destroy_with_parent,                                             type = gtk.messagetype.question,                                             buttons = gtk.buttonstype.yes_no,                                             message_format =                                              'are sure want quit?')     print ('quit confirmation dialog running.')     confirmation_response = confirmation_dialog.run()                                                   if confirmation_response == gtk.responsetype.yes:         print ('you have clicked on yes, quiting..')         gtk.main_quit()     elif confirmation_response == gtk.responsetype.no:         print ('you have clicked on no')     confirmation_dialog.destroy()     print ('quit confirmation dialog destroyed.')  # show dialog when button clicked. def on_button_about_clicked(widget):     print ('about')  # perform addition when button clicked. def on_button_add_clicked(widget):     print ('add')  # main function def main():     builder = gtk.builder()     builder.add_from_file('calculatorgui.glade')      signalhandler = {     'on_main_window_destroy': gtk.main_quit,     'on_button_quit_clicked': on_button_quit_clicked,     'on_button_about_clicked': on_button_about_clicked,     'on_button_add_clicked': on_button_add_clicked     }     builder.connect_signals(signalhandler)      main_window = builder.get_object('main_window')       main_window.show_all()      gtk.main()     print ('program finished!')  # if program not imported module, run. if __name__ == '__main__':     main() 

ingredients of calculatorgui.glade file: http://pastebin.com/k2wb7z4r

a screenshot of program:

enter image description here

for started program in python recommend try program guis hand not tools glade, wxglade...

doing hard way teach need know program structure. simple programs this.