1

I am using python 3.6 , wxPython '4.0.3 msw (phoenix) wxWidgets 3.0.5' on Windows 10. I am trying to set the size of the button but it is not working. The size of frame was changing but not that of the button. The button takes up the whole frame. Here is my code:

import wx
app = wx.App()
panel = wx.Panel()
mystyles = wx.SYSTEM_MENU | wx.CLOSE_BOX | wx.CAPTION | wx.MINIMIZE_BOX
fra = wx.Frame(panel,title="learning",style=mystyles,size=(200,200))
button = wx.Button(fra,label="Press Me",size=(10,10))
fra.Show()
app.MainLoop()

Here is a screenshot:

Button

0

1 Answer 1

1

Here you are creating a frame inside a panel. The normal practise is for the opposite. Try this:

import wx
app = wx.App()
mystyles = wx.SYSTEM_MENU | wx.CLOSE_BOX | wx.CAPTION | wx.MINIMIZE_BOX
fra = wx.Frame(None, title="learning", style=mystyles, size=(200, 200))
panel = wx.Panel(fra)
button = wx.Button(panel, label="Press Me", size=(10, 10))
fra.Show()
app.MainLoop()

I have also replaced the parent of the button to be the panel.

The None in the frame constructor means it is the main window. (If it isn't the main window put the main window as a argument in place of None)

Sign up to request clarification or add additional context in comments.

2 Comments

I just started learning it today so i don't know much about it. It is nearly same as tkinter. However thanks.
I am having the same problem, however I don't even create the panel. I only create the frame, and am trying to put the button inside of the frame. However it takes up the whole screen too. Why does this occur?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.