473,386 Members | 1,736 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.

wxPython AND PyGame: IMAGES

tharden3
916 512MB
Ok, I've been going through these tutorials for both PyGame and wxPython, but I've hit a big speed bump. In each tutorial, I've gotten to the point where I need to "import" or "load" images for various purposes (animation, icons, etc.). Each time I follow the tutorial, I can't quite get it right... please don't tell me "Hey, you can't use the pictures in the tutorial example because those are not the directories, paths, or pics that are on your computer". I know that already. Help me to figure out (please provide code and examples in your posts) how to use images on my computer. I will provide the code in the tutorials, links to the tutorials, and the error I get from my code. This might require you to answer with some depth and instruction, but it would be a big help to me and my progress in learning python!

P.S.
- When I show my code, it is not the only thing I tried. Don't just tell me I'm wrong, provide a clear answer.
- It is basically the same problem in wxPython and PyGame... it's all about making images work in these apps

I've been studying and working very hard in python, and this has really stopped me dead in my tracks. Please provide whatever help you can.

What the tutorial says to do:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/python
  2.  
  3. # menuexample.py
  4.  
  5. import wx
  6.  
  7. class MenuExample(wx.Frame):
  8.     def __init__(self, parent, id, title):
  9.         wx.Frame.__init__(self, parent, id, title, size=(250, 150))
  10.  
  11.         menubar = wx.MenuBar()
  12.         file = wx.Menu()
  13.         quit = wx.MenuItem(file, 1, '&Quit\tCtrl+Q')
  14.         quit.SetBitmap(wx.Bitmap('icons/exit.png'))
  15.         file.AppendItem(quit)
  16.  
  17.         self.Bind(wx.EVT_MENU, self.OnQuit, id=1)
  18.  
  19.         menubar.Append(file, '&File')
  20.         self.SetMenuBar(menubar)
  21.  
  22.         self.Centre()
  23.         self.Show(True)
  24.  
  25.     def OnQuit(self, event):
  26.         self.Close()
  27.  
  28. app = wx.App()
  29. MenuExample(None, -1, '')
  30. app.MainLoop()
What I tried (but not the only thing I tried):

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/python
  2.  
  3. # menuexample.py
  4.  
  5. import wx
  6.  
  7. class MenuExample(wx.Frame):
  8.     def __init__(self, parent, id, title):
  9.         wx.Frame.__init__(self, parent, id, title, size=(250, 150))
  10.  
  11.         menubar = wx.MenuBar()
  12.         file = wx.Menu()
  13.         quit = wx.MenuItem(file, 1, '&Quit\tCtrl+Q')
  14.         quit.SetBitmap(wx.Bitmap('C:\Python24\tony.bmp'))
  15.         file.AppendItem(quit)
  16.  
  17.         self.Bind(wx.EVT_MENU, self.OnQuit, id=1)
  18.  
  19.         menubar.Append(file, '&File')
  20.         self.SetMenuBar(menubar)
  21.  
  22.         self.Centre()
  23.         self.Show(True)
  24.  
  25.     def OnQuit(self, event):
  26.         self.Close()
  27.  
  28. app = wx.App()
  29. MenuExample(None, -1, '')
  30. app.MainLoop()
Jul 12 '08 #1
2 2821
jlm699
314 100+
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/python
  2. # menuexample.py
  3.  
  4. import wx
  5.  
  6. class MenuExample(wx.Frame):
  7.     def __init__(self, parent, id, title):
  8.         wx.Frame.__init__(self, parent, id, title, size=(250, 150))
  9.  
  10.         menubar = wx.MenuBar()
  11.         file = wx.Menu()
  12.         quit = wx.MenuItem(file, 1, '&Quit\tCtrl+Q')
  13.         quit.SetBitmap(wx.Bitmap('C:\Python24\tony.bmp'))
  14.         file.AppendItem(quit)
  15.  
  16.         self.Bind(wx.EVT_MENU, self.OnQuit, id=1)
  17.  
  18.         menubar.Append(file, '&File')
  19.         self.SetMenuBar(menubar)
  20.  
  21.         self.Centre()
  22.         self.Show(True)
  23.  
  24.     def OnQuit(self, event):
  25.         self.Close()
  26.  
  27. app = wx.App()
  28. MenuExample(None, -1, '')
  29. app.MainLoop()
I've gotten bitmaps to work before in wxPython, however I've never attempted such an act in PyGame. In order to get a bitmap into a wx-friendly format I used the following:
Expand|Select|Wrap|Line Numbers
  1. bmp = wx.Image('Splash.bmp', wx.BITMAP_TYPE_BMP, -1).ConvertToBitmap()
  2.  
And then in your code you would use
Expand|Select|Wrap|Line Numbers
  1.         quit.SetBitmap(bmp)
  2.  
Please let us know if that helped at all... there are many things about bitmaps that make image handling touchy. Most of the problems you'll face revolve around how Python recognizes the image file. That's why I needed to specify the type of the image with wx.BITMAP_TYPE_BMP
Jul 14 '08 #2
tharden3
916 512MB
I've gotten bitmaps to work before in wxPython, however I've never attempted such an act in PyGame. In order to get a bitmap into a wx-friendly format I used the following:
Expand|Select|Wrap|Line Numbers
  1. bmp = wx.Image('Splash.bmp', wx.BITMAP_TYPE_BMP, -1).ConvertToBitmap()
  2.  
And then in your code you would use
Expand|Select|Wrap|Line Numbers
  1.         quit.SetBitmap(bmp)
  2.  
Please let us know if that helped at all... there are many things about bitmaps that make image handling touchy. Most of the problems you'll face revolve around how Python recognizes the image file. That's why I needed to specify the type of the image with wx.BITMAP_TYPE_BMP
Thanks for the help. I did end up getting this to work (in wxPython, not pygame), but with PNG and JPEG files. But I'll be able to use this in the future.
Jul 14 '08 #3

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

Similar topics

4
by: jblazi | last post by:
I am having this problem: I use Python for my teaching and right now we are trying to implement some sort of very simple graphical game the pupils can play across the Internet. For this, we use...
3
by: Erik Bethke | last post by:
Hello All, I am having a great time with python and pygame, and last night I took a long look at the wxPython demo. I think that rocks as well. So now, my question is do wxPython and PyGame...
3
by: tlviewer | last post by:
hello, The script below is a prototype for loading playing card images from the bitmap resource in cards.dll (WinXP) I like the idea of not keeping copies of the images as files. I'm able...
2
by: DK | last post by:
I'm somewhat new to Python but not to programming. I just want to know if it's possible to have a SINGLE wxPython frame containing two sections where one will contain widgets and the other will...
2
by: Blaze Bresko | last post by:
Hi, I am trying to make a game using either livewires or pygame. The game is tetris. Right now I have gotten the program to a point where everything works (as in user input, score, lines, etc),...
1
by: liuliuliu | last post by:
hi -- sorry if this is trivial -- but how do you make a screenshot of a pygame display? i have a surface which is basically the entire visible screen -- how do you write this surface as an image...
4
by: Iacopo.Marmo | last post by:
Hi! I need to manipulate multicolor strings, i.e. strings with a color associated with each letter. Any suggestions?
0
by: eric dexter | last post by:
I am looking for a simple example of moving a bitmap on a wxpython canvas. I am wanting to do something that most people do with pygame (because pygame is slow but working on my computer may be my...
5
by: defn noob | last post by:
Im using PyGame to draw images of graphs and trees. Howver right now i am looping using: while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() ...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.