PDA

View Full Version : Create a button in python



ubudog
January 30th, 2010, 07:23 PM
Hello, I am very new to python, just started yesterday, and have managed to get a window up. I want to make a button inside the window. I have tried
button = gtk.Button() and it still doesn't work. Is there anything else I need to do? This is my current code:
#!/usr/bin/python
import gtk
import pygtk
window = gtk.Window()
window.set_title("My Program")
button = gtk.Button()
window.show_all()
gtk.main()

Thanks for any help

steeleyuk
January 30th, 2010, 07:53 PM
#!/usr/bin/python
import gtk
import pygtk

window = gtk.Window()
window.set_title("My Program")
button = gtk.Button("Button text here")
window.add(button)
window.show_all()

gtk.main()

I've added some text to the button as well, otherwise it will show up as a tiny square in a tiny window. All you had missing was window.add(button). :)

ubudog
January 30th, 2010, 08:48 PM
Thanks for helping a noob!! :p:p:p