473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

python gui programming

Hi,

I am a newbie in python programming. I have just been playing with Python for two weeks now, and I really feel comfortable with Python. Now I am learning the GUI programming with python. And I am working with pywin to create the gui. I found it is hard to learn pywin. It seems like you need to have a solid background of MFC in order to learn the gui side of pywin. Is there any tutorials out there can help my learning curve? I have been searching out there, and I can not really find anything good. Thank you for any pointers.
Mar 19 '07 #1
14 2713
bartonc
6,596 Expert 4TB
Hi,

I am a newbie in python programming. I have just been playing with Python for two weeks now, and I really feel comfortable with Python. Now I am learning the GUI programming with python. And I am working with pywin to create the gui. I found it is hard to learn pywin. It seems like you need to have a solid background of MFC in order to learn the gui side of pywin. Is there any tutorials out there can help my learning curve? I have been searching out there, and I can not really find anything good. Thank you for any pointers.
You are so right about PythonWin! I don't know anybody who uses it. For beginners, there's Tkinter. I'm using wxPython. Here is a good place to start with Tkinter. Have fun!
Mar 19 '07 #2
Cool. Thanks for the advice. I thought it is just me. I will look into wxPython and wxWidgets too.
Mar 19 '07 #3
bartonc
6,596 Expert 4TB
Cool. Thanks for the advice. I thought it is just me. I will look into wxPython and wxWidgets too.
You are welcome. Come on back if you ever have a need for wxPython help. Welocme to TheScripts!
Mar 19 '07 #4
Hi,

I am still playing around with pywin (gui). And I found out that if you want to run a dialog box. You can use the "DoModal" function. Once the function called, you can not made any changes anymore to the gui. This is not really what i have in mind. Says.. I want a dialog box to spit out text like "Welcome", and then after that it will change to the progress bar. Basically I would like to be able to change the gui dynamically according to certain situation. Is that possible at all? If it is, would anyone give me some directions on how to do it? Thanks in advance
Mar 19 '07 #5
bartonc
6,596 Expert 4TB
Hi,

I am still playing around with pywin (gui). And I found out that if you want to run a dialog box. You can use the "DoModal" function. Once the function called, you can not made any changes anymore to the gui. This is not really what i have in mind. Says.. I want a dialog box to spit out text like "Welcome", and then after that it will change to the progress bar. Basically I would like to be able to change the gui dynamically according to certain situation. Is that possible at all? If it is, would anyone give me some directions on how to do it? Thanks in advance
Yes, it is possible. Of course, I don't know if the MFC will let you do it, but wx will. All dialogs in wxPython are just ordinary frames with a couple of added features (like ShowModal() for waiting until the user clicks a button before the main program will continue). If it is modal, all the action would come from the dialog subclass. Non-modal dialogs can be changed dynamically from the main program. Hope that helps.
Mar 19 '07 #6
Cool. So it is possible after all. I am just frustated with Pywin. Having spend so much time on it, but can not find anything or get anything to work at all. I will be start looking at wxPython. And I think I have to concentrate on the "Non-modal dialog". Again, thank you very much for the pointer.
Mar 19 '07 #7
Yes, it is possible. Of course, I don't know if the MFC will let you do it, but wx will. All dialogs in wxPython are just ordinary frames with a couple of added features (like ShowModal() for waiting until the user clicks a button before the main program will continue). If it is modal, all the action would come from the dialog subclass. Non-modal dialogs can be changed dynamically from the main program. Hope that helps.
Is it possible to change the text without user interactions? I would like to have the text in the gui changed according to the main program (mostly it is a linear based program). Here is what I tried so far, but I have no success at all:

Expand|Select|Wrap|Line Numbers
  1. import wx
  2.  
  3. class MyForm (wx.Panel):
  4.     def __init__ (self, parent, id):
  5.         wx.Panel.__init__(self, parent, id)
  6.         self.info = wx.StaticText (self, 10, "This is my first text", wx.Point (10, 10))
  7.  
  8.     def changeStaticText (self, newText):
  9.         self.info.SetLabel (newText)
  10.  
  11.  
  12. app = wx.PySimpleApp()
  13. frame = wx.Frame (None, -1, "Fun with wxPython")
  14. myForm = MyForm (frame, -1)
  15. frame.Show (True)
  16. app.MainLoop()
  17.  
  18. # Change the text dynamically after the panel is created.
  19. myForm.changeStaticText ("NEW line of text")
  20.  
I really appreciate any helps that I can get. Thank you.
Mar 20 '07 #8
bartonc
6,596 Expert 4TB
Is it possible to change the text without user interactions? I would like to have the text in the gui changed according to the main program (mostly it is a linear based program). Here is what I tried so far, but I have no success at all:

Expand|Select|Wrap|Line Numbers
  1. import wx
  2.  
  3. class MyForm (wx.Panel):
  4.     def __init__ (self, parent, id):
  5.         wx.Panel.__init__(self, parent, id)
  6.         self.info = wx.StaticText (self, 10, "This is my first text", wx.Point (10, 10))
  7.  
  8.     def changeStaticText (self, newText):
  9.         self.info.SetLabel (newText)
  10.  
  11.  
  12. app = wx.PySimpleApp()
  13. frame = wx.Frame (None, -1, "Fun with wxPython")
  14. myForm = MyForm (frame, -1)
  15. frame.Show (True)
  16. app.MainLoop()
  17.  
  18. # Change the text dynamically after the panel is created.
  19. myForm.changeStaticText ("NEW line of text")
  20.  
I really appreciate any helps that I can get. Thank you.
It's really no problem. That's what we're here for.
Expand|Select|Wrap|Line Numbers
  1.         self.info.SetLabel (newText)
  2.         self.info.Update()
Should do the trick. I haven't tried it, but I had to call update on static text to get the background color to change. Let me know it that works for you.
Mar 20 '07 #9
bartonc
6,596 Expert 4TB
It's really no problem. That's what we're here for.
Expand|Select|Wrap|Line Numbers
  1.         self.info.SetLabel (newText)
  2.         self.info.Update()
Should do the trick. I haven't tried it, but I had to call update on static text to get the background color to change. Let me know it that works for you.
By the way, did you pick up the docs and demos while you were getting the core wxPython package?
Mar 20 '07 #10
bartonc
6,596 Expert 4TB
Is it possible to change the text without user interactions? I would like to have the text in the gui changed according to the main program (mostly it is a linear based program). Here is what I tried so far, but I have no success at all:

Expand|Select|Wrap|Line Numbers
  1. import wx
  2.  
  3. class MyForm (wx.Panel):
  4.     def __init__ (self, parent, id):
  5.         wx.Panel.__init__(self, parent, id)
  6.         self.info = wx.StaticText (self, 10, "This is my first text", wx.Point (10, 10))
  7.  
  8.     def changeStaticText (self, newText):
  9.         self.info.SetLabel (newText)
  10.  
  11.  
  12. app = wx.PySimpleApp()
  13. frame = wx.Frame (None, -1, "Fun with wxPython")
  14. myForm = MyForm (frame, -1)
  15. frame.Show (True)
  16. app.MainLoop()
  17.  
  18. # Change the text dynamically after the panel is created.
  19. myForm.changeStaticText ("NEW line of text")
  20.  
I really appreciate any helps that I can get. Thank you.
I just had a look at one of my dialogs that changes the text on a static text object: There's no need to call Update(). It looks like you never call your function. Try adding a button that calls your function in its OnButton handler.
Or
Expand|Select|Wrap|Line Numbers
  1. app = wx.PySimpleApp()
  2. frame = wx.Frame (None, -1, "Fun with wxPython")
  3. myForm = MyForm (frame, -1)
  4. frame.Show (True)
  5. wx.FutureCall(2500, myForm.changeStaticText, "time's up")
  6. app.MainLoop()
  7.  
to automatically change after 2.5 seconds.
Mar 20 '07 #11
I just had a look at one of my dialogs that changes the text on a static text object: There's no need to call Update(). It looks like you never call your function. Try adding a button that calls your function in its OnButton handler.
Or
Expand|Select|Wrap|Line Numbers
  1. app = wx.PySimpleApp()
  2. frame = wx.Frame (None, -1, "Fun with wxPython")
  3. myForm = MyForm (frame, -1)
  4. frame.Show (True)
  5. wx.FutureCall(2500, myForm.changeStaticText, "time's up")
  6. app.MainLoop()
  7.  
to automatically change after 2.5 seconds.
Thank you for the reply. I tried out your code and it works.

I did pick up the docs and manual when I am downloading the wxPython core. I have gone through some tutorials about wxPython (i.e. http://wiki.wxpython.org/index.cgi/Getting_Started). I think I get it on how to code event handling for the gui if it is waiting for someone input.

I tried reverse the order of the codes.

From

Expand|Select|Wrap|Line Numbers
  1. wx.FutureCall(2500, myForm.changeStaticText, "time's up")
  2. app.MainLoop()
  3.  
to

Expand|Select|Wrap|Line Numbers
  1. app.MainLoop()
  2. wx.FutureCall(2500, myForm.changeStaticText, "time's up")
  3.  
And this does not really works for me. It think it is because once the MainLoop is called, the gui can not be "changed" anymore. So say if I have a gui and also a main program. The gui does not know what to expect and when to expect. It all depends on the main program. The gui will just display the results that the main program get. I have done some research on this, and it seems that to get both the gui and the main program working, i have to code them with threading. So the main program will just run by itself, and the gui will just wait for the result or command from main program. If this is not the right way to do it or there is other way to do it, please let me know

Once again, thank you very much.
Mar 20 '07 #12
bartonc
6,596 Expert 4TB
Thank you for the reply. I tried out your code and it works.

I did pick up the docs and manual when I am downloading the wxPython core. I have gone through some tutorials about wxPython (i.e. http://wiki.wxpython.org/index.cgi/Getting_Started). I think I get it on how to code event handling for the gui if it is waiting for someone input.

I tried reverse the order of the codes.

From

Expand|Select|Wrap|Line Numbers
  1. wx.FutureCall(2500, myForm.changeStaticText, "time's up")
  2. app.MainLoop()
  3.  
to

Expand|Select|Wrap|Line Numbers
  1. app.MainLoop()
  2. wx.FutureCall(2500, myForm.changeStaticText, "time's up")
  3.  
And this does not really works for me. It think it is because once the MainLoop is called, the gui can not be "changed" anymore. So say if I have a gui and also a main program. The gui does not know what to expect and when to expect. It all depends on the main program. The gui will just display the results that the main program get. I have done some research on this, and it seems that to get both the gui and the main program working, i have to code them with threading. So the main program will just run by itself, and the gui will just wait for the result or command from main program. If this is not the right way to do it or there is other way to do it, please let me know

Once again, thank you very much.
The trick is to build all the frames of your program, then call Mainloop() and perform ALL tasks in subclasses of toplevel frames (ie Dialogs and Frames).
Once Mainloop() is called, it does just that: it loops until your program terminates.
Mar 20 '07 #13
Thanks for the tips. I will definitely give it a try.
Mar 21 '07 #14
bartonc
6,596 Expert 4TB
Thanks for the tips. I will definitely give it a try.
You are welcome. It makes me think that I'll have to sit down and write an article on event driven programming vs scripting (when I get some time).
Mar 21 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
226
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type...
49
by: Ville Vainio | last post by:
I don't know if you have seen this before, but here goes: http://text.userlinux.com/white_paper.html There is a jab at Python, though, mentioning that Ruby is more "refined". -- Ville...
38
by: kbass | last post by:
In different articles that I have read, persons have constantly eluded to the productivity gains of Python. One person stated that Python's productivity gain was 5 to 10 times over Java in some in...
68
by: Lad | last post by:
Is anyone capable of providing Python advantages over PHP if there are any? Cheers, L.
35
by: John Coleman | last post by:
Greetings, I have a rough classification of languages into 2 classes: Zen languages and tool languages. A tool language is a language that is, well, a *tool* for programming a computer. C is the...
17
by: MilkmanDan | last post by:
I'll be a college freshman this fall, attending Florida Institute of Tech studying electrical engineering. I was considering taking some classes in programming and computer science, and I...
852
by: Mark Tarver | last post by:
How do you compare Python to Lisp? What specific advantages do you think that one has over the other? Note I'm not a Python person and I have no axes to grind here. This is just a question for...
0
by: wesley chun | last post by:
Need to get up-to-speed with Python as quickly as possible? Come join me, Wesley Chun, author of Prentice-Hall's bestseller "Core Python Programming," for another comprehensive intro course plus a...
0
by: wesley chun | last post by:
*** FINAL REMINDER also, the course begins on monday immediately following the *free* CodeCamp conference http://siliconvalley-codecamp.com (click Program => Sessions to see all the talks)... 5...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.