"Hello, world"?

eb303 eric.brunel.pragmadev at gmail.com
Wed Oct 28 11:40:49 CET 2009


On Oct 28, 11:23 am, Francesco Bochicchio <bieff... at gmail.com> wrote:
> On 28 Ott, 10:40, Gilles Ganault <nos... at nospam.com> 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



More information about the Python-list mailing list