python类Button()的实例源码

hellogtk.py 文件源码 项目:python-3-for-absolute-begs 作者: Apress 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def __init__(self):
        # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)

        # Set the title of the window to "Graphic User Interface"
        self.window.set_title("Graphic User Interface")

        # Create a handler for delete_event that immediately quits GTK.
        self.window.connect("delete_event", self.delete_event)

        # Set the border width of the window.
        self.window.set_border_width(6)

        # Create a box to pack the widgets into. The box is an invisible 
        # container, which is used to arrange the widgets inside it.
        self.box1 = gtk.HBox(gtk.FALSE, 0)

        # Put the box into the main window.
        self.window.add(self.box1)

        # Create a new button with the label "Hello".
        self.button1 = gtk.Button("Hello")

        # Now when the button is clicked, we call the self.callback method 
        # with a pointer to "the Hello button" as its argument.
        self.button1.connect("clicked", self.callback, "the Hello button")

        # Instead of add(), we pack this button into the invisible box, 
        # which has been packed into the window.
        self.box1.pack_start(self.button1, gtk.TRUE, gtk.TRUE, 0)

        # Always remember this step, this tells GTK to actually display the 
        # button.
        self.button1.show()

        # Do these same steps again to create a second button
        self.button2 = gtk.Button("Quit")

        # This time, delete_event is called and the window exits.
        self.button2.connect("clicked", self.delete_event, "the Quit button")
        self.box1.pack_start(self.button2, gtk.TRUE, gtk.TRUE, 0)

        # The order in which the buttons are shown is not really important, 
        # but it is recommended to show the window last, so that everything 
        # displays at once.
        self.button2.show()
        self.box1.show()
        self.window.show()
fanim_timeline.py 文件源码 项目:gimp-fanim 作者: douglasvini 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _setup_playbackbar(self):
        playback_bar = gtk.HBox()
        button_size = 30
        stock_size = gtk.ICON_SIZE_BUTTON

        # play button
        ## image
        image_play = gtk.Image()
        image_play.set_from_stock(gtk.STOCK_MEDIA_PLAY,stock_size)
        image_pause = gtk.Image()
        image_pause.set_from_stock(gtk.STOCK_MEDIA_PAUSE,stock_size)
        ## append the images to a list to be used later on
        self.play_button_images.append(image_play)
        self.play_button_images.append(image_pause)
        ## button
        b_play = gtk.Button()
        b_play.set_image(image_play)
        b_play.set_size_request(button_size,button_size)

        b_tostart = Utils.button_stock(gtk.STOCK_MEDIA_PREVIOUS,stock_size)
        b_toend = Utils.button_stock(gtk.STOCK_MEDIA_NEXT,stock_size)
        b_prev = Utils.button_stock(gtk.STOCK_MEDIA_REWIND,stock_size)
        b_next = Utils.button_stock(gtk.STOCK_MEDIA_FORWARD,stock_size)

        b_repeat = Utils.toggle_button_stock(gtk.STOCK_REFRESH,stock_size)

        # connecting the button with callback
        b_play.connect('clicked',self.on_toggle_play)
        b_repeat.connect('toggled',self.on_replay)

        b_next.connect('clicked',self.on_goto,NEXT,True)
        b_prev.connect('clicked',self.on_goto,PREV,True)
        b_toend.connect('clicked',self.on_goto,END,True)
        b_tostart.connect('clicked',self.on_goto,START,True)


        # add to the disable on play list
        w = [b_repeat,b_prev,b_next,b_tostart,b_toend]
        map(lambda x: self.widgets_to_disable.append(x),w)
        self.play_bar = playback_bar

        # set the tooltips
        b_play.set_tooltip_text("Animation play/pause")
        b_repeat.set_tooltip_text("Animation replay active/deactive")
        b_prev.set_tooltip_text("To the previous frame")
        b_next.set_tooltip_text("To the next frame")
        b_tostart.set_tooltip_text("To the start frame")
        b_toend.set_tooltip_text("To the end frame")

        # packing everything in gbar
        playback_bar.pack_start(b_tostart,False,False,0)
        playback_bar.pack_start(b_prev,False,False,0)
        playback_bar.pack_start(b_play,False,False,0)
        playback_bar.pack_start(b_next,False,False,0)
        playback_bar.pack_start(b_toend,False,False,0)
        playback_bar.pack_start(b_repeat,False,False,0)

        return playback_bar
importdialog.py 文件源码 项目:chirp_fork 作者: mach327 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def make_adjust(self):
        hbox = gtk.HBox(True, 2)

        incr = gtk.Button("+100")
        incr.connect("clicked", self.__incrnew, 100)
        incr.set_size_request(50, 25)
        incr.show()
        hbox.pack_start(incr, 0, 0, 0)

        incr = gtk.Button("+10")
        incr.connect("clicked", self.__incrnew, 10)
        incr.set_size_request(50, 25)
        incr.show()
        hbox.pack_start(incr, 0, 0, 0)

        incr = gtk.Button("+1")
        incr.connect("clicked", self.__incrnew, 1)
        incr.set_size_request(50, 25)
        incr.show()
        hbox.pack_start(incr, 0, 0, 0)

        decr = gtk.Button("-1")
        decr.connect("clicked", self.__incrnew, -1)
        decr.set_size_request(50, 25)
        decr.show()
        hbox.pack_start(decr, 0, 0, 0)

        decr = gtk.Button("-10")
        decr.connect("clicked", self.__incrnew, -10)
        decr.set_size_request(50, 25)
        decr.show()
        hbox.pack_start(decr, 0, 0, 0)

        decr = gtk.Button("-100")
        decr.connect("clicked", self.__incrnew, -100)
        decr.set_size_request(50, 25)
        decr.show()
        hbox.pack_start(decr, 0, 0, 0)

        auto = gtk.Button(_("Auto"))
        auto.connect("clicked", self.__autonew)
        auto.set_size_request(50, 25)
        auto.show()
        hbox.pack_start(auto, 0, 0, 0)

        revr = gtk.Button(_("Reverse"))
        revr.connect("clicked", self.__revrnew)
        revr.set_size_request(50, 25)
        revr.show()
        hbox.pack_start(revr, 0, 0, 0)

        frame = gtk.Frame(_("Adjust New Location"))
        frame.show()
        frame.add(hbox)
        hbox.show()

        return frame


问题


面经


文章

微信
公众号

扫码关注公众号