0
votes

It's pretty simple what I'm trying to accomplish here.

Say you put down 320 in the left textbox. That means the width of the window will be 320px. Same applies for height, except for the right textbox.

However when I debug I get this error.

Traceback (most recent call last):
  File "./app.py", line 37, in change_size
    self.win.set_size_request(width,height)
TypeError: an integer is required

Here's the code.

#!/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.connect("destroy", gtk.main_quit)
    vbox = gtk.VBox(spacing=4)
    hbox = gtk.HBox(spacing=4)

    self.entry = gtk.Entry()
    self.entry2 = gtk.Entry()
    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", gtk.main_quit)
    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 = self.entry.get_text()
    height = self.entry2.get_text()
    self.win.set_size_request(width,height)

app()
gtk.main()
1
Why don't use SpinButton instead of Entry? It has better interface for numbers, unless you need to make it int (like this case), because SpinButton returns float, not int. - saeedgnu

1 Answers

1
votes

That's because get_text returns a string, but set_size_request requires integers. Simple fix:

    width = int(self.entry.get_text())
    height = int(self.entry2.get_text())