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 2851 - #!/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 wxPython.
Now it has turned out that wxPython does not implement wxWidget sockets,
so we have to use Python sockets instead. Implementing a separate thread
for this would be too complicated and I am going to use the wxIdle event
to do the socket...
|
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 work together?
How is the windows event loop managed? How is the display window
managed?
|
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 to extract the card images as files, then load
them in pygame as a surface, but I keep getting errors
|
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 host an animation done using PyGame.
More specifically, I want to have a list of names of animations on the
left and depending on what is selected, run the PyGame animation in the
main area.
|
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), except I can't
get more than one block to work. Right now I have the user playing a
game where a single block falls at a time instead of one of the seven
different patterns. I was curious how you would program the seperate
images to fall together...
| |
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 file during
specific events in the script execution? image format doesnt matter.
thanks! christine
|
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 graphics card). I have been searching through google and I haven't found that much (found some tkinter stuff though)... any help would be nice.
|
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()
screen.fill(screencolor)
pygame.draw.circle(screen, linecolor, (500, 20), 12, 0)
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |