Results 1 to 2 of 2

Thread: [SOLVED] [wxPython] Displaying a Bitmap

  1. #1
    Join Date
    May 2008
    Beans
    1,029

    [SOLVED] [wxPython] Displaying a Bitmap

    I've found some tutorials on how to display a picture, but that's as far as the tutorials go. I need to display a picture in a sub-window (I guess you would call it), and I can't figure out how.

    Here is my script:
    PHP Code:
    import wx

    MenuItem_exit 
    101
    MenuItem_about 
    100

    class MainWindow(wx.Frame):
        
    def __init__(selfparentIDtitle):
            
    wx.Frame.__init__(selfparentIDtitle,
                            
    wx.DefaultPositionwx.Size(800600),
                            
    wx.DEFAULT_FRAME_STYLE & ~ (wx.RESIZE_BORDER |
                            
    wx.RESIZE_BOX wx.MAXIMIZE_BOX))
            
            
    self.Bind(wx.EVT_CLOSEself.QuitGame)

            
    self.CreateStatusBar()
            
    self.SetStatusText("Active")
            
            
    self.FirePic wx.Bitmap('display/fire.bmp')
            
    #wx.EVT_PAINT(self, self.ShowBack)

            
            
    white wx.Colour(255255255)
            
    black wx.Colour(000)
            
    red wx.Colour(25500)
            
    green wx.Colour(02550)
            
    blue wx.Colour(00255)
            
    yellow wx.Colour(2552550)
            
    dblue wx.Colour(0,0,162)
            
    mygreen wx.Colour(10,133,2)
            
            
    file wx.Menu()
            
    help wx.Menu()
            
            
    screen wx.Window(self, -1, (00), (790349), style=wx.BORDER_SUNKEN)
            
    screen.SetBackgroundColour(mygreen)
            
    #wx.EVT_PAINT(screen, self.ShowBack)

            
    controls wx.Panel(self, -1, (0350), (800250))
            
    north wx.Button(controls, -1"North", (365,5))
            
    south wx.Button(controls, -1"South", (365,55))
            
    east wx.Button(controls, -1"East", (450,30))
            
    west wx.Button(controls, -1"West", (280,30))
            
    search1 wx.Button(controls, -1"Search", (36530))


            
    file.Append(MenuItem_exit"E&xit""Quit the game?")
            
            
    help.Append(MenuItem_about"&About""About the game")
            
            
    MenuBar wx.MenuBar()
            
    MenuBar.Append(file"&File")
            
    MenuBar.Append(help"&Help")
            
            
    self.SetMenuBar(MenuBar)
            
            
    wx.EVT_MENU(selfMenuItem_exitself.QuitGame)
            
    wx.EVT_MENU(selfMenuItem_aboutself.AboutGame)
            
            
    self.Centre()
        
            
        
    def QuitGame(selfevent):
            
    dlg wx.MessageDialog(self
                
    "Do you really want to quit? All information will be lost.",
                
    "Confirm Exit"wx.OK|wx.CANCEL|wx.ICON_QUESTION)
            
    result dlg.ShowModal()
            
    dlg.Destroy()
            if 
    result == wx.ID_OK:
                
    self.Destroy()
        
        
    def ShowBack(self,event):
            
    bg wx.PaintDC(self)
            
    bg.DrawBitmap(self.FirePic00)
        
        
    def AboutGame(selfevent):
            
    about_text "About this Game"
            
    dlg wx.MessageDialog(self"\
    This game\n\
    Created by Deluge 2008"
    ,
                                    
    about_textwx.OK)
            
    dlg.ShowModal()
        

    class 
    Game(wx.App):
        
    def OnInit(self):
            
    frame MainWindow(None, -1"MyGame")
            
    frame.Show(True)
            
    self.SetTopWindow(frame)
            return(
    True)

    app Game(0)
    app.MainLoop() 
    The upper window, called "screen", is where I want the bitmap to be displayed. That's all I want, to display as soon as the program is run. Do I need to use something other than a wx.Window?
    Last edited by dodle; December 3rd, 2008 at 12:32 PM.

  2. #2
    Join Date
    May 2008
    Beans
    1,029

    Re: [wxPython] Displaying a Bitmap

    Got it figured out.
    PHP Code:
    wx.StaticBitmap(selfwx.Bitmap("path/to/bitmap.bmp"), sizepos

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •