Your application looks very nice. Try this code:
-- Get the displays
local displays = GetDisplays()
-- Create a window
local window = CreateWindow("Calculator", 0, 0, 800, 660, displays[1], WINDOW_CENTER | WINDOW_TITLEBAR)-- | WINDOW_RESIZABLE)
-- Create User Interface
local ui = CreateInterface(window)
--Create buttons
local sz = window:ClientSize()
local x = (sz.x - 120) / 2
local y = 50
local sep = 40
-- Create widget
local panel = CreatePanel(50, 50, sz.x - 100, sz.y - 100, ui.background)
panel:SetColor(0, 0, 0, 1)
panel:SetLayout(1, 1, 1, 1)
-- Create text field
local textfield = CreateTextField(70, 10, 600, 30,ui.background);
textfield:SetText("0");
textfield:SetFontScale(2);
textfield:SetColor(0,0,0,1)
-- Row 1
local buttonMC = CreateButton("MC", 30, 30, 70, 70, panel);
local buttonMR = CreateButton("MR", 110, 30, 70, 70, panel);
local buttonM_Plus = CreateButton("M+", 190, 30, 70, 70, panel);
local buttonM_Minus = CreateButton("M-", 270, 30, 70, 70, panel);
-- Row 2
local buttonCE = CreateButton("CE", 30, 110, 70, 70, panel);
local buttonC = CreateButton("C", 110,110, 70, 70, panel);
local buttonPct = CreateButton("%", 190, 110, 70, 70, panel);
local buttonDivide = CreateButton("/",270, 110, 70, 70, panel);
-- Row 3
local button1 = CreateButton("1", 30, 190, 70, 70, panel);
local button2 = CreateButton("2", 110, 190, 70, 70, panel);
local button3 = CreateButton("3", 190, 190, 70, 70, panel);
local buttonMultiply = CreateButton("X", 270, 190, 70, 70, panel);
-- Row 4
local button4 = CreateButton("4", 30, 270, 70, 70, panel);
local button5 = CreateButton("5", 110, 270, 70, 70, panel);
local button6 = CreateButton("6", 190, 270, 70, 70, panel);
local button_Minus = CreateButton("-", 270, 270, 70, 70, panel);
-- Row 5
local button7 = CreateButton("7", 30, 350, 70, 70, panel);
local button8 = CreateButton("8", 110, 350, 70, 70, panel);
local button9 = CreateButton("9", 190, 350, 70, 70, panel);
local button_Plus = CreateButton("+", 270, 350, 70, 70, panel);
-- Row 6
local buttonPlusMinus = CreateButton("+/-", 30, 430, 70, 70, panel);
local button0 = CreateButton("0", 110, 430, 70, 70, panel);
local buttonDecimal = CreateButton(",", 190, 430, 70, 70, panel);
local buttonResult = CreateButton("=", 270, 430, 70, 70, panel);
while true do
local ev = WaitEvent()
if ev.id == EVENT_WIDGETACTION then
if (ev.source == button1 ) then
FirstNum = 1;
if textfield.text == "0" then textfield:SetText("") end
textfield:SetText(textfield.text.."1");
elseif (ev.source == button2) then
FirstNum = 2;
if textfield.text == "0" then textfield:SetText("") end
textfield:SetText(textfield.text.."2");
end
elseif ev.id == EVENT_WINDOWCLOSE then
break
end
end