The Exit App (PyGTK)
Linux tutorials and code.
1 post
Page 1 of 1
In this tutorial. I show you guys how to make a simple window in PyGTK, as well as some functionality it has. Today we're going to add a button onto it, and when we click that button the application closes.
Yep! You guessed it we're going to create that simple, dumb Exit App in Python. Now why are we doing this again?
Well this should help you understand how you'd add vertical box's as well as horizontal box's to position your buttons, and what not.
So lets grab the code we created in this tutorial of just the window.
Now here's the full source code.
Yep! You guessed it we're going to create that simple, dumb Exit App in Python. Now why are we doing this again?
Well this should help you understand how you'd add vertical box's as well as horizontal box's to position your buttons, and what not.
So lets grab the code we created in this tutorial of just the window.
Code: Select all
Now right below window.connect("destroy", gtk.main_quit) we're going to call gtk.HBox(), hbox for short...
#!/usr/bin/env python
import gtk
class app:
def __init__(self):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_position(gtk.WIN_POS_CENTER)
window.set_title("TestApp")
window.set_default_size(200, 10)
window.connect("destroy", gtk.main_quit)
window.show_all()
app()
gtk.main()
Code: Select all
We're then going to add the horizontal box into our window.
hbox = gtk.HBox()
Code: Select all
Now we need to add a button that we'll call exit, and we'll also have it say "Exit" on the button. We will also haft to connect the button and state that when we click it, the application will close.
window.add(hbox)
Code: Select all
Last, but not least it's time to make our button visible.
exit = gtk.Button("Exit")
exit.connect("clicked", gtk.main_quit)
Code: Select all
Easy As That! cooll;hbox.pack_start(exit, True)
Now here's the full source code.
Code: Select all
#!/usr/bin/env python
import gtk
class app:
def __init__(self):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_position(gtk.WIN_POS_CENTER)
window.set_title("TestApp")
window.set_default_size(200, 10)
window.connect("destroy", gtk.main_quit)
hbox = gtk.HBox()
window.add(hbox)
exit = gtk.Button("Exit")
exit.connect("clicked", gtk.main_quit)
hbox.pack_start(exit, True)
window.show_all()
app()
gtk.main()
1 post
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023