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: - #!/usr/bin/python
-
-
# menuexample.py
-
-
import wx
-
-
class MenuExample(wx.Frame):
-
def __init__(self, parent, id, title):
-
wx.Frame.__init__(self, parent, id, title, size=(250, 150))
-
-
menubar = wx.MenuBar()
-
file = wx.Menu()
-
quit = wx.MenuItem(file, 1, '&Quit\tCtrl+Q')
-
quit.SetBitmap(wx.Bitmap('icons/exit.png'))
-
file.AppendItem(quit)
-
-
self.Bind(wx.EVT_MENU, self.OnQuit, id=1)
-
-
menubar.Append(file, '&File')
-
self.SetMenuBar(menubar)
-
-
self.Centre()
-
self.Show(True)
-
-
def OnQuit(self, event):
-
self.Close()
-
-
app = wx.App()
-
MenuExample(None, -1, '')
-
app.MainLoop()
What I tried (but not the only thing I tried): - #!/usr/bin/python
-
-
# menuexample.py
-
-
import wx
-
-
class MenuExample(wx.Frame):
-
def __init__(self, parent, id, title):
-
wx.Frame.__init__(self, parent, id, title, size=(250, 150))
-
-
menubar = wx.MenuBar()
-
file = wx.Menu()
-
quit = wx.MenuItem(file, 1, '&Quit\tCtrl+Q')
-
quit.SetBitmap(wx.Bitmap('C:\Python24\tony.bmp'))
-
file.AppendItem(quit)
-
-
self.Bind(wx.EVT_MENU, self.OnQuit, id=1)
-
-
menubar.Append(file, '&File')
-
self.SetMenuBar(menubar)
-
-
self.Centre()
-
self.Show(True)
-
-
def OnQuit(self, event):
-
self.Close()
-
-
app = wx.App()
-
MenuExample(None, -1, '')
-
app.MainLoop()
2 2821 - #!/usr/bin/python
-
# menuexample.py
-
-
import wx
-
-
class MenuExample(wx.Frame):
-
def __init__(self, parent, id, title):
-
wx.Frame.__init__(self, parent, id, title, size=(250, 150))
-
-
menubar = wx.MenuBar()
-
file = wx.Menu()
-
quit = wx.MenuItem(file, 1, '&Quit\tCtrl+Q')
-
quit.SetBitmap(wx.Bitmap('C:\Python24\tony.bmp'))
-
file.AppendItem(quit)
-
-
self.Bind(wx.EVT_MENU, self.OnQuit, id=1)
-
-
menubar.Append(file, '&File')
-
self.SetMenuBar(menubar)
-
-
self.Centre()
-
self.Show(True)
-
-
def OnQuit(self, event):
-
self.Close()
-
-
app = wx.App()
-
MenuExample(None, -1, '')
-
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: -
bmp = wx.Image('Splash.bmp', wx.BITMAP_TYPE_BMP, -1).ConvertToBitmap()
-
And then in your code you would use
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
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: -
bmp = wx.Image('Splash.bmp', wx.BITMAP_TYPE_BMP, -1).ConvertToBitmap()
-
And then in your code you would use
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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),...
|
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...
|
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?
|
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...
|
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()
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
| |