Custom Window Size Change (PyGTK)

Linux tutorials and code.
5 posts Page 1 of 1
Contributors
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

It's pretty simple, the textbox on the left is width, and the one on the right is the height. Choose the dimensions you want the window to look, and click ok to confirm it, and/or exit to close the app.
app.png
Code: Select all
#!/usr/bin/env python

import gtk

class app:

  def __init__(self):
	self.win = gtk.Window(gtk.WINDOW_TOPLEVEL)
	self.win.set_title("Change Dimensions")
	self.win.set_default_size(235, 60)
	self.win.set_resizable(False)
	self.win.connect("destroy", gtk.main_quit)
	vbox = gtk.VBox(spacing=4)
	hbox = gtk.HBox(spacing=4)
	
	self.entry = gtk.Entry()
	self.entry2 = gtk.Entry()
	self.entry.set_text("width")
	self.entry2.set_text("height")
	hbox.pack_start(self.entry)
	hbox.pack_start(self.entry2)
	
	hbox2 = gtk.HBox(spacing=4)
	ok = gtk.Button("OK")
	ok.connect("clicked", self.change_size)
	hbox2.pack_start(ok)
	exit = gtk.Button("Exit")
	exit.connect("clicked", self.win_hide)
	hbox2.pack_start(exit)
	
	vbox.pack_start(hbox)
	vbox.pack_start(hbox2)
	
	self.win.add(vbox)
	self.win.show_all()
	
  def change_size(self, w):
	width = int(self.entry.get_text())
	height = int(self.entry2.get_text())
	self.win.set_size_request(width,height)
	
  def win_hide(self, w):
	gtk.main_quit()
	
app()
gtk.main()
You do not have the required permissions to view the files attached to this post.
Last edited by mikethedj4 on Sun Jul 17, 2011 4:32 pm, edited 3 times in total.
User avatar
Agust1337
Coding God
Coding God
Posts: 2456
Joined: Fri Feb 19, 2010 8:18 pm

Re: Custom Window Size Change
Agust1337
Hmm, is this for the window it self or for some certain window :P?
You're crazy!
I'm not crazy, my mother had me tested. ~Sheldon Cooper
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

Re: Custom Window Size Change
mikethedj4
It's for the window it'self unless you specify another window.
User avatar
Agust1337
Coding God
Coding God
Posts: 2456
Joined: Fri Feb 19, 2010 8:18 pm

Is it any harder if you could write a name of a window in a text field and change it's size?
You're crazy!
I'm not crazy, my mother had me tested. ~Sheldon Cooper
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

Can you give me an example of what you're trying to figure out?
5 posts Page 1 of 1
Return to “Programming”