-
Notifications
You must be signed in to change notification settings - Fork 17
First App: Hello World
Ward edited this page Sep 25, 2022
·
5 revisions
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:
- All wNim apps need a wApp object, call App() to generate one. For multi-thread apps, call App() for every thread.
- Frame() and Panel() is the constructors, they create wFrame object and wPanel object, etc.
- wFrame is a top-level window. We always need a top-level window before we call app.mainLoop().
- 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.