开发者

Coming from a Visual C# Express IDE/C# programming background, is there a tutorial for creating python applications?

开发者 https://www.devze.com 2022-12-15 19:13 出处:网络
It\'s very overwhelming coming from something that helps you create applications straight forward to something with somewhat convoluted documentation.

It's very overwhelming coming from something that helps you create applications straight forward to something with somewhat convoluted documentation.

Can someone please share a tutorial on how to create a simple Hello World application using Python. No,开发者_C百科 I don't mean command line. I mean a physical window.

I'm trying to learn how to program in Python and so far all I find is command line applications, and I don't really find use for them unless I can visually show off my skills.

So, where can I learn some Python GUI development. People have suggested wxWidgets, PyQT, etc. but once again, that means nothing to me, because I know diddly squat about them.

I need an up to date tutorial. :S


Here's a great tutorial for wxPython (my GUI API of choice: extremely powerful, good community/mailing list, and cross-platform (it wraps the native platform's widgets))

http://wiki.wxpython.org/Getting%20Started

Installing wxpython can be done through a simple setup.exe :

http://downloads.sourceforge.net/wxpython/wxPython2.8-win32-unicode-2.8.10.1-py26.exe or

http://downloads.sourceforge.net/wxpython/wxPython2.8-win32-unicode-2.8.10.1-py25.exe

(depending on python version)

Here's a simple hello world, with a simple event bound to the button.

import wx

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None)
        text = wx.StaticText(self, label="hello, world!")
        button = wx.Button(self, label="press me")
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(text, flag=wx.ALL, border=20)
        sizer.Add(button, flag=wx.ALL, border=20)

        self.SetSizer(sizer)
        self.Layout()
        self.Show(True)
        self.Bind(wx.EVT_BUTTON, self.on_button, button)

    def on_button(self, event):
        wx.MessageBox("Hey!")

if __name__ == "__main__":
    app = wx.App(False)
    f = MyFrame()

or, an even simpler example:

import wx
app = wx.PySimpleApp()
frame = wx.Frame(None, wx.ID_ANY, "Hello World")
frame.Show(True)
app.MainLoop()
    app.MainLoop()
0

精彩评论

暂无评论...
验证码 换一张
取 消