[PyWin32] "Hello, world"?

Discussion in 'Python' started by Gilles Ganault, Oct 28, 2009.

  1. Hello

    I'm reading O'Reily's "Python Programming on Win32", but couldn't find
    a simple example on how to create a window with just a label and
    pushbutton.

    If someone has such a basic example handy, I'm interested.

    Thank you.
     
    Gilles Ganault, Oct 28, 2009
    #1
    1. Advertising

  2. Gilles Ganault

    Tim Golden Guest

    Gilles Ganault wrote:
    > Hello
    >
    > I'm reading O'Reily's "Python Programming on Win32", but couldn't find
    > a simple example on how to create a window with just a label and
    > pushbutton.


    Well, you might mean this:

    <code>
    import win32api

    win32api.MessageBox (None, "Hello, World!", "Greetings")

    </code>

    but that obviously has limited possibilities for growth.
    You can change the messages; you can play with combinations
    of buttons; but that's about it.

    Although I can provide a cut-down example, I think that these days
    it would be quite rare to produce a raw-Windows GUI: you'd either
    be using a .NET technology like the WPF or leveraging (as they
    say in other parts of the world) an existing toolkit such as
    Qt, wx or <insert your presentation toolkit of choice here>.

    I suppose what I'm saying is that knowing the way in which
    raw Windows GUI works is becoming increasingly irrelevant.
    But I'm happy to produce something if you're still keen.

    TJG
     
    Tim Golden, Oct 28, 2009
    #2
    1. Advertising

  3. Re: "Hello, world"?

    On 28 Ott, 10:40, Gilles Ganault <> wrote:
    > Hello
    >
    > I'm reading O'Reily's "Python Programming on Win32", but couldn't find
    > a simple example on how to create a window with just a label and
    > pushbutton.
    >


    This is probably because maybe the book addresses how to use python to
    do windows-specific
    stuff (like using a COM interface) and presumes a basic knowledge of
    python in the reader
    (just guessing, never read the book )


    > If someone has such a basic example handy, I'm interested.
    >
    > Thank you.



    There are as many way to do it as many GUI toolkits for python you can
    find (and there are
    many) although they all share a similar structure. Here is the one for
    Tkinter, which is the
    default python GUI toolkit. The example is copied verbatim from
    the python on-line documentation ( section "Graphical User Interfaces
    with Tk" of "The Python Standard Library").



    Ciao
    ------
    FB

    from Tkinter import *

    class Application(Frame):
    def say_hi(self):
    print "hi there, everyone!"

    def createWidgets(self):
    self.QUIT = Button(self)
    self.QUIT["text"] = "QUIT"
    self.QUIT["fg"] = "red"
    self.QUIT["command"] = self.quit

    self.QUIT.pack({"side": "left"})

    self.hi_there = Button(self)
    self.hi_there["text"] = "Hello",
    self.hi_there["command"] = self.say_hi

    self.hi_there.pack({"side": "left"})

    def __init__(self, master=None):
    Frame.__init__(self, master)
    self.pack()
    self.createWidgets()

    root = Tk()
    app = Application(master=root)
    app.mainloop()
    root.destroy()
     
    Francesco Bochicchio, Oct 28, 2009
    #3
  4. Gilles Ganault

    eb303 Guest

    Re: "Hello, world"?

    On Oct 28, 11:23 am, Francesco Bochicchio <> wrote:
    > On 28 Ott, 10:40, Gilles Ganault <> wrote:
    >
    > > Hello

    >
    > > I'm reading O'Reily's "Python Programming on Win32", but couldn't find
    > > a simple example on how to create a window with just a label and
    > > pushbutton.

    >
    > This is probably because maybe the book addresses how to use python to
    > do windows-specific
    > stuff (like using a COM interface) and presumes a basic knowledge of
    > python in the reader
    > (just guessing, never read the book )
    >
    > > If someone has such a basic example handy, I'm interested.

    >
    > > Thank you.

    >
    > There are as many way to do it as many GUI toolkits for python you can
    > find (and there are
    > many) although they all share a similar structure. Here is the one for
    > Tkinter, which is the
    > default python GUI toolkit. The example is copied verbatim from
    > the python on-line documentation ( section "Graphical User Interfaces
    > with Tk" of "The Python Standard Library").
    >
    > Ciao
    > ------
    > FB
    >
    > from Tkinter import *
    >
    > class Application(Frame):
    > def say_hi(self):
    > print "hi there, everyone!"
    >
    > def createWidgets(self):
    > self.QUIT = Button(self)
    > self.QUIT["text"] = "QUIT"
    > self.QUIT["fg"] = "red"
    > self.QUIT["command"] = self.quit
    >
    > self.QUIT.pack({"side": "left"})
    >
    > self.hi_there = Button(self)
    > self.hi_there["text"] = "Hello",
    > self.hi_there["command"] = self.say_hi
    >
    > self.hi_there.pack({"side": "left"})
    >
    > def __init__(self, master=None):
    > Frame.__init__(self, master)
    > self.pack()
    > self.createWidgets()
    >
    > root = Tk()
    > app = Application(master=root)
    > app.mainloop()
    > root.destroy()


    Or way simpler:
    ---
    from Tkinter import *
    root = Tk()
    Label(root, text='Hello world!').pack(side=TOP)
    Button(root, text='Quit', command=root.quit).pack(side=BOTTOM)
    root.mainloop()
    ---

    HTH
     
    eb303, Oct 28, 2009
    #4
  5. Gilles Ganault

    CM Guest

    Re: "Hello, world"?

    On Oct 28, 5:40 am, Gilles Ganault <> wrote:
    > Hello
    >
    > I'm reading O'Reily's "Python Programming on Win32", but couldn't find
    > a simple example on how to create a window with just a label and
    > pushbutton.
    >
    > If someone has such a basic example handy, I'm interested.
    >
    > Thank you.


    In wxPython (which you would have to download and install), it could
    be something like:

    import wx

    class Dialog1(wx.Dialog):
    def __init__(self, parent):
    wx.Dialog.__init__(self, id=-1, name='', parent=parent,
    pos=wx.Point(132, 174), size=wx.Size(149, 80),
    style=wx.DEFAULT_DIALOG_STYLE, title='')

    self.staticText1 = wx.StaticText(id=-1,
    label=u'Hello, World', name='', parent=self,
    pos=wx.Point(40, 16), size=wx.Size(59, 13), style=0)

    if __name__ == '__main__':
    app = wx.PySimpleApp()
    dlg = Dialog1(None)
    try:
    dlg.ShowModal()
    finally:
    dlg.Destroy()
    app.MainLoop()
     
    CM, Oct 28, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2Vhbg==?=

    Server Error in '/Hello World' Application

    =?Utf-8?B?U2Vhbg==?=, Jul 20, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    371
    Ben Lucas
    Jul 20, 2004
  2. =?Utf-8?B?cmFuZHkgY29sbGlucw==?=

    ASP.NET 2.0: "hello world" page fails with "Failed to map the path

    =?Utf-8?B?cmFuZHkgY29sbGlucw==?=, Apr 15, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    5,611
    eagle1140
    Apr 13, 2011
  3. vijay
    Replies:
    8
    Views:
    757
  4. Roy
    Replies:
    6
    Views:
    702
    Roedy Green
    Jan 7, 2008
  5. Larry
    Replies:
    27
    Views:
    495
    Michele Dondi
    Jan 25, 2005
Loading...

Share This Page