Problems about my newbie code.( using pygtk )

Pedro Rodriguez pedro_rodriguez at club-internet.fr
Mon Jan 20 06:17:29 EST 2003


On Mon, 20 Jan 2003 11:34:02 +0100, asho wrote:

> hi...
> I started to use the gtk with python to write some gui programs.
> 
> 
> my goal is to make a program window with two buttons.
> 
> Codes are listed below
> 
> #!/usr/bin/env python
> 
> # this is a translation of "Hello World III" from the GTK manual, #
> using gtk.py
> 
> from gtk import *
> import os
> 
> def vcdrip(*args):
>         #command = "vcdxrip --cdrom-device=/dev/cdrom -p" command =
>         "hehe"
>         os.system(command)
>         window.destroy()
> 
> def destroy(*args):
>     window.hide()
>     mainquit()
> 
> window = GtkWindow(WINDOW_TOPLEVEL)
> window.connect("destroy", destroy)
> window.set_border_width(50)
> 
> button = GtkButton("vcdrip")
> button.connect("clicked",vcdrip)
> window.add(button)
> button.show()
> 
> button2 = GtkButton("exit")
> button2.connect("clicked",destroy)
> window.add(button2)
> button2.show()
> 
> window.show_all()
> 
> mainloop()
> 
> When I run this program , it only appears a button with vcdrip.
> 
> Is there anything wrong with my ocde?? Please help me to solve the
> problem.
> 

I think that you can only add one widget to a GtkWindow (it is a GtkBin)
an that is why you get a warning message when you run your application :
Gtk-CRITICAL **: file gtkbin.c: line 217 (gtk_bin_add): assertion `bin->child == NULL'
failed.

Usually you add a container widget that manage the layout of sub widgets like a
GtkVBox.

from gtk import *
import os

def vcdrip(*args):
        #command = "vcdxrip --cdrom-device=/dev/cdrom -p"
        command = "hehe"
        os.system(command)
        window.destroy()

def destroy(*args):
    window.hide()
    mainquit()

window = GtkWindow(WINDOW_TOPLEVEL)
window.connect("destroy", destroy)
window.set_border_width(50)

v = GtkVBox()  # added 
window.add(v)  # added

button = GtkButton("vcdrip")
button.connect("clicked",vcdrip)
v.add(button)  # changed
button.show()

button2 = GtkButton("exit")
button2.connect("clicked",destroy)
v.add(button2) # changed
button2.show()

window.show_all()

mainloop()

Don't forget there is also a mailing list for pygtk :
http://www.daa.com.au/mailman/listinfo/pygtk

Pedro




More information about the Python-list mailing list