torayeff
torayeff

Reputation: 9702

Direct runnig python GUI scrips (wxpython)

Hello Guys! I started learning python GUI development. Let's say I have this script:

import wx

app = wx.App()

win = wx.Frame(None, title="Simple Editor", size=(410, 335))
bkg = wx.Panel(win)

loadButton = wx.Button(bkg, label="Open")
saveButton = wx.Button(bkg, label="Save")
fileName = wx.TextCtrl(bkg)
contents = wx.TextCtrl(bkg, style=wx.TE_MULTILINE | wx.HSCROLL)

hbox = wx.BoxSizer()
hbox.Add(fileName, proportion=1, flag=wx.EXPAND)
hbox.Add(loadButton, proportion=0, flag=wx.LEFT, border=5)
hbox.Add(saveButton, proportion=0, flag=wx.LEFT, border=5)

vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(hbox, proportion=0, flag=wx.EXPAND | wx.ALL, border=5)
vbox.Add(contents, proportion=1, flag=wx.EXPAND | wx.LEFT |wx.BOTTOM | wx.RIGHT, border=5) 

bkg.SetSizer(vbox)
win.Centre()
win.Show()
app.MainLoop()

This script does nothing, just shows windows and etc. To run this script, basically I do from terminal by:

python gui_test.py

How can I run it directly, without invoking terminal, I mean running just clicking with mouse?

Upvotes: 1

Views: 502

Answers (1)

jdi
jdi

Reputation: 92569

  1. Rename gui_test.py -> gui_test.pyw
  2. Double click

.pyw is the fancy windows way of telling the python script to execute without also opening a console


For linux systems, make the script executable:

chmod a+x gui_test.py

Also, don't forget to include the "shebang" line at the top of any executable script. This allows you to run the script without having to specify the interpreter:

#!/usr/bin/env python

Then from a terminal:

./gui_test.py

Upvotes: 4

Related Questions