# Determining window size in Python

**URL:** <https://forum.inductiveautomation.com/t/determining-window-size-in-python/749>\
**Category:** Archived Topics\
**Created:** [July 29, 2008, 11:48pm UTC](https://forum.inductiveautomation.com/t/determining-window-size-in-python/749 "2008-07-29T23:48:43Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathan](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@nathan](https://forum.inductiveautomation.com/u/nathan)\
**Post date:** [July 29, 2008, 11:48pm UTC](https://forum.inductiveautomation.com/t/determining-window-size-in-python/749/1 "2008-07-29T23:48:43Z")

</div>

Can you determine the x and y size of a window in script?

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [July 30, 2008, 3:35am UTC](https://forum.inductiveautomation.com/t/determining-window-size-in-python/749/2 "2008-07-30T03:35:10Z")

</div>

Sure, just get a handle to the window like this:

```auto
win = fpmi.gui.getWindow('MyWindow')
```

and then get the size params like this:

`x = win.location.x
y = win.location.y
width = win.size.width
height = win.size.height`

---

<div class="post-metadata">

**Author:** ![harryting](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@harryting](https://forum.inductiveautomation.com/u/harryting)\
**Post date:** [October 14, 2008, 5:09pm UTC](https://forum.inductiveautomation.com/t/determining-window-size-in-python/749/3 "2008-10-14T17:09:57Z")

</div>

The code:

x = win.location.x  
y = win.location.y

bombs out for me but the rest of it works.

I have found it’s easier to work with window sizing by selecting the window then use CTRL-P to see and adjust size.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [October 15, 2008, 3:47am UTC](https://forum.inductiveautomation.com/t/determining-window-size-in-python/749/4 "2008-10-15T03:47:35Z")

</div>

I think nathan was talking about accessing the window size at runtime. How exactly did it “bomb out”? Did you include the snippet of code from the first code section too?

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [October 15, 2008, 3:45pm UTC](https://forum.inductiveautomation.com/t/determining-window-size-in-python/749/5 "2008-10-15T15:45:02Z")

</div>

I’ll preface this reply by saying I don’t have much clue what I’m doing here, but checking in the Java documentation shows that location should be followed by brackets. The following code seems to work:

`win = fpmi.gui.getWindow('MyWindow')
x = win.location().x
y = win.location().y
width = win.size.width
height = win.size.height
print x,y
print width,height`  
I also noticed that ‘location()’ is in the deprecated list and has been replaced by ‘getLocation()’ - does this matter here, Carl?

Al

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [October 16, 2008, 3:53am UTC](https://forum.inductiveautomation.com/t/determining-window-size-in-python/749/6 "2008-10-16T03:53:23Z")

</div>

So, whats going on here is that the location() function is interfering with Python’s automatic JavaBean property access support. Here is an example: If I have a Java class with functions like getFoo() and setFoo(String foo), then in Python I can say:

objectInstance.foo, referencing “foo” as if it were a variable, not a pair of getter/setter functions. This is part of the JavaBean spec.

So, normally when you access the variable “win.location” Python is really going to call the function win.getLocation(). But, the presence of a “location()” function on Window is throwing off the JavaBean stuff, and so you are accessing that function directly, which is why you need the parens to make it work.

More than you wanted to know, eh?

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [October 16, 2008, 7:21am UTC](https://forum.inductiveautomation.com/t/determining-window-size-in-python/749/7 "2008-10-16T07:21:06Z")

</div>

😮

I stand informed. I’m assuming then that you should really be directly calling the getLocation() function here.

---

<div class="post-metadata">

**Author:** ![harryting](https://avatars.discourse-cdn.com/v4/letter/h/bb73d2/32.png) [@harryting](https://forum.inductiveautomation.com/u/harryting)\
**Post date:** [October 16, 2008, 1:57pm UTC](https://forum.inductiveautomation.com/t/determining-window-size-in-python/749/8 "2008-10-16T13:57:41Z")

</div>

Oh ya, that works now, thanks.

Where do you to look at Java documentation?

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [October 16, 2008, 2:10pm UTC](https://forum.inductiveautomation.com/t/determining-window-size-in-python/749/9 "2008-10-16T14:10:39Z")

</div>

Hi harryting,

You could look at [http://java.sun.com/javase/reference/api.jsp](http://java.sun.com/javase/reference/api.jsp) under Core API Docs version 6, but I warn you, there is a ton of stuff in there! (and if you know as little about Java as I do it may only confuse things more!)

Al

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [October 16, 2008, 9:02pm UTC](https://forum.inductiveautomation.com/t/determining-window-size-in-python/749/10 "2008-10-16T21:02:00Z")

</div>

Somewhat related, do I have access to the Move Forward, Move Backward, Move to Front, Move to Back properties programatically? I found that it could be useful while using the paint component.

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [October 16, 2008, 10:01pm UTC](https://forum.inductiveautomation.com/t/determining-window-size-in-python/749/11 "2008-10-16T22:01:28Z")

</div>

Step7,

I’m in so far over my head here that I can’t see the light anymore, but for what it’s worth, I’ve been able to read the z-order of components on the screen using code like

`root = event.source.parent
z1 = root.getComponentZOrder(event.source.parent.getComponent('Button'))
z2 = root.getComponentZOrder(event.source.parent.getComponent('Text Field'))
print "Button z-order = %d" % (z1)
print "Text Field z-order = %d" % (z2)`  
I then superimposed the 2 objects and tried to swap their z-order using the following code:

`root.setComponentZOrder(event.source.parent.getComponent('Button'),z2)
root.setComponentZOrder(event.source.parent.getComponent('Text Field'),z1)`  
However, the controls only refreshed when I moved the mouse over them.

That’s as far as I’ve got!

Al

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [October 16, 2008, 11:31pm UTC](https://forum.inductiveautomation.com/t/determining-window-size-in-python/749/12 "2008-10-16T23:31:49Z")

</div>

Hey, thanks Al. I’ll be able to get that working somehow. That’s just what I was looking for.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [October 19, 2008, 6:31pm UTC](https://forum.inductiveautomation.com/t/determining-window-size-in-python/749/13 "2008-10-19T18:31:49Z")

</div>

You probably just need to call .repaint() on the container after changing its children’s Z-order.

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [October 20, 2008, 8:09am UTC](https://forum.inductiveautomation.com/t/determining-window-size-in-python/749/14 "2008-10-20T08:09:40Z")

</div>

Carl,

Adding`root.repaint()`at the end of the previous code did the trick ![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:")
