1+ import unreal_engine as ue
2+
3+ from unreal_engine .classes import Image , CanvasPanelSlot , TextBlock , WidgetBlueprintFactory
4+ from unreal_engine .structs import AnchorData , Anchors , Vector2D , Margin
5+
6+ import time
7+
8+ widget = WidgetBlueprintFactory ().factory_create_new ( "/Game/W_MyWidgetBlueprint" + str (int (time .time ())) )
9+
10+ widget .modify ()
11+
12+ widgetTree = widget .WidgetTree
13+
14+
15+ slot = CanvasPanelSlot ('' , widgetTree )
16+ image = Image ('' , widgetTree )
17+
18+ slot .Content = image
19+
20+ slot2 = CanvasPanelSlot ('' , widgetTree )
21+ text_block = TextBlock ('' , widgetTree )
22+ text_block .Text = 'Hello World'
23+
24+ slot2 .Content = text_block
25+
26+ widgetTree .RootWidget .Slots = [slot , slot2 ]
27+ widgetTree .AllWidgets = [ widgetTree .RootWidget , image , text_block ]
28+
29+ slot .LayoutData = AnchorData (Offsets = Margin (Left = 0 , Top = 0 , Right = 300 , Bottom = 300 ))
30+
31+ slot2 .LayoutData = AnchorData (Anchors = Anchors (Minimum = Vector2D (X = 0.5 , Y = 0.5 ), Maximum = Vector2D (X = 1 , Y = 1 )))
32+
33+ widget .post_edit_change ()
34+
35+ ue .compile_blueprint (widget )
36+
37+ ue .open_editor_for_asset (widget )
0 commit comments