banner



How To Change The Background Colour In Python Code

Member Avatar

Guys, I am trying to change the background color of my window in WxPython.
Here is what I got:
Why doesn't it work?

                      import wx  class my_window(wx.Frame):          def __int__(self, parent, id):         wx.Frame.__int__(self,parent,id,'My Window', size=(300,200))         self.Colours()           def Colours(self):         self.pnl1.SetBackgroundColour(wx.BLACK)            if __name__ == "__main__":     app=wx.PySimpleApp()     frame=my_window(parent=None,id=-1)     frame.Show()     app.MainLoop()                    
  • 3 Contributors
  • forum 5 Replies
  • 9,215 Views
  • 6 Years Discussion Span
  • comment Latest Post Latest Post by Rufus_1

Recommended Answers

                        import wx  class my_window(wx.Frame):     def __init__(self, parent, id):  #error __int__         wx.Frame.__init__(self,parent,id,'My Window', size=(300,200))          #Panel for frame         self.panel = wx.Panel(self)         self.SetBackgroundColour('blue')  if __name__ == "__main__":     app=wx.PySimpleApp()     frame=my_window(parent=None,id=-1)     frame.Show()     app.MainLoop()                      

Jump to Post

It work fine for me,it has no error so it should work for you to.
In your first code both __int__ statement was wrong should be __init__

                        import wx  class my_window(wx.Frame):     def __init__(self, parent, id):         wx.Frame.__init__(self,parent,id,'My Window', size=(300,200))              self.SetBackgroundColour('BLACK')  if __name__ == "__main__":     app=wx.PySimpleApp()     frame=my_window(parent=None,id=-1)     frame.Show()     app.MainLoop()                      

Jump to Post

All 5 Replies

Member Avatar

                          import wx  class my_window(wx.Frame):     def __init__(self, parent, id):  #error __int__         wx.Frame.__init__(self,parent,id,'My Window', size=(300,200))          #Panel for frame         self.panel = wx.Panel(self)         self.SetBackgroundColour('blue')  if __name__ == "__main__":     app=wx.PySimpleApp()     frame=my_window(parent=None,id=-1)     frame.Show()     app.MainLoop()                        

Member Avatar

                            import wx  class my_window(wx.Frame):     def __init__(self, parent, id):  #error __int__         wx.Frame.__init__(self,parent,id,'My Window', size=(300,200))          #Panel for frame         self.panel = wx.Panel(self)         self.SetBackgroundColour('blue')  if __name__ == "__main__":     app=wx.PySimpleApp()     frame=my_window(parent=None,id=-1)     frame.Show()     app.MainLoop()                          

snippsat when I ran your code I got the same result with yours that I did with mine.
Just a gray window pops up.

Member Avatar

It work fine for me,it has no error so it should work for you to.
In your first code both __int__ statement was wrong should be __init__

                          import wx  class my_window(wx.Frame):     def __init__(self, parent, id):         wx.Frame.__init__(self,parent,id,'My Window', size=(300,200))              self.SetBackgroundColour('BLACK')  if __name__ == "__main__":     app=wx.PySimpleApp()     frame=my_window(parent=None,id=-1)     frame.Show()     app.MainLoop()                        

Edited by snippsat because: n/a

Member Avatar

Thanks snippsat I got it to work.
It wouldn't work when I ran it with:

                          #Panel for frame self.panel = wx.Panel(self)                        

and also __int__ instead of __init__ like you said :)


Here is my final code:

                          import wx         class my_window(wx.Frame):            def __init__(self, parent, id):         wx.Frame.__init__(self,parent,id,'My Window', size=(300,200))         self.SetBackgroundColour(wx.BLUE)         if __name__ == "__main__":       app=wx.PySimpleApp()       frame=my_window(parent=None,id=-1)       frame.Show()       app.MainLoop()                        

Edited by HoneyBadger because: n/a

Member Avatar

When you added the panel, you didn't call SetBackgroundColour on the panel, but you were still using the Frame's method. Instead of:

                                                      #Panel for frame     self.panel = wx.Panel(self)     self.SetBackgroundColour('blue')                        

It should be:

                                                      #Panel for frame     self.panel = wx.Panel(self)     self.panel.SetBackgroundColour('blue')                        

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.

How To Change The Background Colour In Python Code

Source: https://www.daniweb.com/programming/software-development/threads/331067/wxpython-changing-background-color

Posted by: farrersawles93.blogspot.com

0 Response to "How To Change The Background Colour In Python Code"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel