Monday, 2024-04-29, 4:16 PM
Welcome Guest

Distance Education

[ New messages · Members · Forum rules · Search · RSS ]
  • Page 1 of 1
  • 1
Forum moderator: Christos  
Forum » Software Development » RE:Work » Python GUI Help
Python GUI Help
Elliot81Date: Thursday, 2009-08-13, 5:29 PM | Message # 1
Private
Group: Users
Messages: 2
Awards: 0
Reputation: 0
Status: Offline
Hi guys smile
Need a bit of help on what these commands do:
Code

get()
sticky =  
as well as varibles that end with  END, example: 0.0, END

Yes im behind i know :?
 
HaydenJohnsDate: Friday, 2009-08-14, 12:58 PM | Message # 2
Lieutenant colonel
Group: Checked
Messages: 123
Awards: 0
Reputation: 0
Status: Offline
Get() returns whatever the thing contains. It's syntax is:

classobject.object.get(start, end)

So, say you had a textbox defined as self.mytextbox. This code would check if the value of the box was "text". If so, it prints a notice to the command line.

if self.mytextbox.get(0.0,END) == "text":
_____print "The textbox says "text"

The 0.0 thing specifies where Get() starts searching - column and row (not sure witch is first), check in your python book. So, 0.0 specifies that it starts at row 0, column 0 (i.e. the start). END simply tells Get() to stop searching at wherever the thing ends, rather than at a specific point.

As for the sticky thing, I found this with a quick google search. From what I read, it simply specifies where the button goes if the grid is larger than the button (when there's loose space in the grid around it) - if it jumps to the top-left, or goes to the center, etc.
Not exactly sure though, as I gave up on getting grid() to work in the python activities and just ended up using place() instead. That's covered in the page as well.

Added (2009-08-14, 12:58 Pm)
---------------------------------------------
Oh, and I also found this, which shows how to stop people resizing the window. I haven't tested it yet, but further reading on google suggest that it disables the maximize button as well.

Might be useful for keeping the window nice and tidy.


~ Click it
 
Dr4c0niusDate: Friday, 2009-08-14, 5:29 PM | Message # 3
Major
Group: Users
Messages: 96
Awards: 2
Reputation: 0
Status: Offline
Grid works kind of like an excel spreadsheet, except each cell is only as large as the largest object in it.

Well, thats how I think of it tongue


Oderint dum metuant

<locokamil> Your belief system is thermodynamically unsound.

 
HaydenJohnsDate: Saturday, 2009-08-15, 7:50 AM | Message # 4
Lieutenant colonel
Group: Checked
Messages: 123
Awards: 0
Reputation: 0
Status: Offline
I'll stick to place(), thank-you-very-much tongue

It's easier to keep track of where everything is, but it requires you to draw out the GUI on paper and label the distances between each item first (e.g. button1 is 20 px below textbox1)


~ Click it
 
Dr4c0niusDate: Saturday, 2009-08-15, 8:52 AM | Message # 5
Major
Group: Users
Messages: 96
Awards: 2
Reputation: 0
Status: Offline
The thing I don't get about Tkinter is the way it uses pixels in some things, then just stops in others. Like in width, a width of 20 is NOT 20 pixels. If it kept stuff purely in pixels, I'd use place() more.

Oderint dum metuant

<locokamil> Your belief system is thermodynamically unsound.

 
HaydenJohnsDate: Saturday, 2009-08-15, 9:24 AM | Message # 6
Lieutenant colonel
Group: Checked
Messages: 123
Awards: 0
Reputation: 0
Status: Offline
Are you sure? I wrote this up as an experiment:

Sorry about the lack of comments, I was too lazy to write any.

Code
from Tkinter import *

class Window:
     def __init__(self, master):
         frame=Frame(master)
         frame.place(width=200, height=200)

         button1=Button(master)
         button1.place(x=0, y=0, width = 100, height=100)

          
         button2=Button(master)
         button2.place(x=100, y=0, width = 100, height=100)

         button3=Button(master)
         button3.place(x=0, y=100, width = 100, height=100)

         button1=Button(master)
         button1.place(x=100, y=100, width = 100, height=100)

root=Tk()
root.title("Test to see if draconius is right")
root.geometry("200x200")
root.resizable(0,0)
app=Window(root)
root.mainloop(1)

The pixel counts seem to match up. Or did you mean something else?

Added (2009-08-15, 9:20 Am)
---------------------------------------------
Keep in mind that x=200 is actually pixel 201 from the left hand side - it counts from 0.

Got me confused for a moment tongue

Added (2009-08-15, 9:24 Am)
---------------------------------------------
Oh, and adding resizable(0,0) does get rid of the maximise button - I threw it into this little app to kill two birds with one stone.


~ Click it
 
Dr4c0niusDate: Sunday, 2009-08-16, 9:15 AM | Message # 7
Major
Group: Users
Messages: 96
Awards: 2
Reputation: 0
Status: Offline
Ok, don't worry about that. I just took a screenshot of an app i wrote, and a button with a width of 20 is about 30 pixels wide. THATS what I cant understand. Maybe Tkinter hates me?

Oderint dum metuant

<locokamil> Your belief system is thermodynamically unsound.

 
HaydenJohnsDate: Sunday, 2009-08-16, 1:02 PM | Message # 8
Lieutenant colonel
Group: Checked
Messages: 123
Awards: 0
Reputation: 0
Status: Offline
Ah, you mean that tkinter's pixel count isn't the actual pixel count?

I just tested that by altering the window size so it read root.geometry("1024x200") to test if it was 1024 pixels across the screen (my resolution is, obviously, 1024x768. It looked about right, but it got jolted across because of some configurations on my Laptop. (tried to fit it into the one workstation - including the border of the window).

And if that's how you tested, then perhaps the answer is in the screenshot? You could test that by taking a screenshot of an image that you know has a certain pixel count, and comparing it to the resolution of the screenshot.


~ Click it
 
Dr4c0niusDate: Tuesday, 2009-08-18, 1:33 PM | Message # 9
Major
Group: Users
Messages: 96
Awards: 2
Reputation: 0
Status: Offline
Done. And i also counted the pixels manually using an external screen at a (very) low resolution. I'm running 16:9 widescreen, it could be that?

Oderint dum metuant

<locokamil> Your belief system is thermodynamically unsound.

 
HaydenJohnsDate: Tuesday, 2009-08-18, 2:51 PM | Message # 10
Lieutenant colonel
Group: Checked
Messages: 123
Awards: 0
Reputation: 0
Status: Offline
Beats me. I'm not about to run more tests now (in the middle of a very nasty bug in my SAC, been trying to get it out but no luck yet) so I'm a little bit frustrated at the moment.

~ Click it
 
Forum » Software Development » RE:Work » Python GUI Help
  • Page 1 of 1
  • 1
Search: