Skip to content

First App: Hello World

Ward edited this page Sep 25, 2022 · 5 revisions

Code

import wNim

# import submodules one by one can speed up compilation time
# import wNim/[wApp, wFrame, wPanel, wStaticText]

let app = App()
let frame = Frame(title="wNim Frame")
let panel = Panel(frame)
let label = StaticText(panel, label="Hello World")

label.center() # Center label window in parent's client area
frame.center() # Center frame window in screen
frame.show() # A frame is hidden on creation by default.

app.mainLoop() # or app.run()

Let's explain some basic principle for wNim apps:

  1. All wNim apps need a wApp object, call App() to generate one. For multi-thread apps, call App() for every thread.
  2. Frame() and Panel() is the constructors, they create wFrame object and wPanel object, etc.
  3. wFrame is a top-level window. We always need a top-level window before we call app.mainLoop().
  4. app.mainLoop() will start the message loop for a window program. It will end if there is no any top-level window. In this program, it ends when we close the frame by click [X] button.

Screenshot

image

Clone this wiki locally