Skip to content

Change Window Size and Position

Ward edited this page Oct 4, 2019 · 1 revision

Code

Specify on creation:

import wNim/[wApp, wFrame, wPanel, wStaticText]

let app = App()
let frame = Frame(title="wNim Frame", size=(400, 300))
let panel = Panel(frame)
let label = StaticText(panel, label="Hello World", pos=(50, 50))

echo frame.getSize()

frame.center()
frame.show()
app.mainLoop()

Specify after creation:

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")

frame.setSize(400, 300)
label.setPosition(50, 50)

# Here we can also use wSize, wPoint tuple:
# frame.setSize((400, 300))
# label.setPosition((50, 50))

echo frame.getSize() # returns a wSize tuple

frame.center()
frame.show()
app.mainLoop()

For every methods in format of proc setXXXX(self: Class, x: Type) or proc getXXXX(self: Class): Type, We can write it in this way:

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")

frame.size = (400, 300)
label.position = (50, 50)

echo frame.size

frame.center()
frame.show()
app.mainLoop()

Output

(width: 400, height: 300)

Screenshot

image

Clone this wiki locally