How to Size a Python Frame
When you create a Python program with a graphical user interface, you need to set the size of the frame or window that will appear on the user's screen. Python has two major GUI modules: Tkinter and wxPython. Setting the size of a frame is a different process in the two modules.
Instructions
-
Tkinter
-
1
Open your Python script.
-
2
Type:
root = Tk()
frame = Frame(root, width=###, height=###)
frame.pack()root.mainloop()
Replace "###" with the width and height you want the frame to have in pixels.
-
-
3
Save and close your script.
wxPython
-
4
Open the Python script in which you want to set the size of a frame.
-
5
Type:
from wxPython.wx import *
def example(event): print 'what will be in the frame'
class MyApp(wxApp):
def OnInit(self):
win_id = wxNewId()
win = wxFrame(NULL, win_id, 'frame title',
size=wxSize(###, ###))
btn_id = wxNewId()
btn = wxButton(win, btn_id, 'example')
EVT_BUTTON(btn, btn_id, example)
win.Show(true)
return trueapp = MyApp()
app.MainLoop()Replace the number symbols with the width and height you want the frame to have. The first "###" represents width. The second is height. The other values should change depending on what you want to do in the frame.
-
6
Save your program.
-
1