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 2856 - #!/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: 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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |