A few notes:
I wouldn't consider
NewButton a unique enough name to occupy the global namespace. It's common practice to prefix the name of your addon to any global (including frame names) you create to prevent collisions with other addons or even the DefaultUI.
In most cases, you can create your frames in the main part of your code. You don't need to wait for any special event to do so.
If both offsets for
UIObject:SetPoint() are zero, they can be omitted. (If either are non-zero, you must provide both.)
Button:SetPushedTexture() replaces the normal texture when the button is in that state. To have a persistent normal texture, you'll have to create another texture object to show it.
The push texture for that path doesn't need alpha blending. Alpha blending converts gradients of white/black depending on the mode to transparent. If a texture already contains transparency, this causes the image to do unintentional things.
You don't need to call
UIObject:Show() after creating an object. It is already shown by default providing it has a valid anchor and size. (Size can also be defined by setting more than one anchor if desired.)
You should use
print() instead of
DEFAULT_CHAT_FRAME:AddMessage(). This lets other addons redirect through their own print handler without causing taint issues.
With these in mind, here's an example.
Lua Code:
local ExampleButton=CreateFrame("Button",nil,UIParent);
ExampleButton:SetPoint("CENTER");
ExampleButton:SetSize(40,40);
ExampleButton:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square","ADD");
ExampleButton:SetPushedTexture("Interface\\Buttons\\UI-Quickslot-Depress");
local ExampleButtonIcon=ExampleButton:CreateTexture(nil,"BACKGROUND");
ExampleButtonIcon:SetAllPoints(ExampleButton);
ExampleButtonIcon:SetTexture("Interface\\Icons\\INV_Misc_ArmorKit_17");
ExampleButton:SetScript("OnClick",function(self,button)
print("Button Clicked");
end);
PS: ActionButtons do some funky thing with setting a custom size for their normal texture. This texture is the empty box you see if you have them shown on your multi-bars. If you look close enough, you might see a double-border on occupied ones. This is a side effect of that implementation. In the example above, this was removed for the sake of simplicity.