Guest User

Untitled

a guest
Feb 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. #!usr/bin/python
  2.  
  3. #test
  4.  
  5. import pygtk
  6. pygtk.require ('2.0')
  7. import gtk
  8. import random
  9.  
  10. class Gtest:
  11.     def __init__(self):
  12.         self.window1 = gtk.Window(gtk.WINDOW_TOPLEVEL)
  13.         #creo window1
  14.        
  15.         self.window1.connect("delete_event", self.delete_event)
  16.         self.window1.connect("destroy", self.destroy)
  17.         #due metodi che vengono applicati a window1
  18.        
  19.         self.window1.set_resizable(True)
  20.         self.window1.set_title("ariccchime")
  21.         self.window1.set_default_size(400, 400)
  22.         #attributi di window1
  23.        
  24.         self.button = gtk.Button("cliccami")
  25.         #crea un bottone
  26.         self.button.connect("clicked", self.cliccato)
  27.        
  28.         #attributi e segnali del bottone
  29.        
  30.         self.fix = gtk.Fixed()
  31.         self.fix.put(self.button, 15, 25)
  32.  
  33.        
  34.         self.window1.add(self.fix)
  35.         #non aggiungere window1.add(button) perche' Fixed ci pensa da solo
  36.         #self.window1.add(self.button)
  37.        
  38.         self.window1.show_all()
  39.         #mostra window1 e il bottone
  40.    
  41.     def cliccato(self, widget, data=None):
  42.         self.button.set_label("mi sposto")
  43.         self.fix.put(self.button, random.randrange(0, 400), random.randrange(0, 400))
  44.        
  45.     def delete_event(self, widget, event, data=None):
  46.         return False
  47.        
  48.     def destroy(self, widget, data = None):
  49.         return gtk.main_quit()
  50.    
  51.     def main(self):
  52.         gtk.main()
  53.        
  54. if __name__ == "__main__":
  55.    
  56.     test = Gtest()
  57.     test.main()
Add Comment
Please, Sign In to add comment