请教各位:
在 Eto forms in Python中,Lable这个包含的属性怎么查询?例如,我想换个文字颜色,TextColor该如何操作,或是文字对齐VerticalAlignment,VerticalAlignment.Center这个center其它的对齐方式都有哪些?谢谢
你没导入模块,你看看你的Label都是forms.Label,都是同一个名称空间下的,肯定也需要forms,一下嘛
没明白,这个是直接复制的教程里的;
另外,假如说增加个颜色的属性 应该如何操作?
谢谢
其实我上面已经回答了你的问题了。点进链接就能查到。
http://pages.picoe.ca/docs/api/html/T_Eto_Forms_Label.htm
1:显示没定义是因为需要你单独调用一下,你也没单独导入这个枚举。所以需要像图片一样调用。
2:咋找字体颜色,我最开始也说了,如果当前类没有,就往父类找。
Label类继承了 TextControl,看名字大概就能猜到和Text有关系,点进去看看就能找到了。
http://pages.picoe.ca/docs/api/html/P_Eto_Forms_TextControl_TextColor.htm
如果你还没搞定,麻烦传一下代码案例,给你简单演示一下。
万分感谢月神 按照您的提示文字对齐格式已经搞定,颜色还是没搞定,还请指点一下;
#coding=utf-8
Imports
import Rhino
import scriptcontext
import System
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
T1 = “314”
SampleEtoRoomNumber dialog class
class SampleEtoRoomNumberDialog(forms.Dialog[bool]):
# Dialog box Class initializer
def __init__(self):
# Initialize dialog box 初始化对话框
self.Title = '房间录入程序'
self.Padding = drawing.Padding(10)
self.Resizable = True
# Create controls for the dialog
self.m_label = forms.Label()
self.m_label.Text = '输入房间号:'
self.m_label.VerticalAlignment = forms.VerticalAlignment.Center
self.m_label.TextAlignment = forms.TextAlignment.Center
self.m_label.Textcolor = forms.TextControl.TextColor.PropertyType.A
self.m_textbox = forms.TextBox(Text = T1)
# Create the default button
self.DefaultButton = forms.Button(Text = '行')
self.DefaultButton.Click += self.OnOKButtonClick
# Create the abort button
self.AbortButton = forms.Button(Text = '退出')
self.AbortButton.Click += self.OnCloseButtonClick
# Create a table layout and add all the controls
layout = forms.DynamicLayout()
layout.Spacing = drawing.Size(5, 5)
layout.AddRow(self.m_label, self.m_textbox)
layout.AddRow(None) # spacer
layout.AddRow(self.DefaultButton, self.AbortButton)
# Set the dialog content
self.Content = layout
# Start of the class functions
# Get the value of the textbox
def GetText(self):
return self.m_textbox.Text
# Close button click handler
def OnCloseButtonClick(self, sender, e):
self.m_textbox.Text = ""
self.Close(False)
# OK button click handler
def OnOKButtonClick(self, sender, e):
if self.m_textbox.Text == "":
self.Close(False)
else:
self.Close(True)
## End of Dialog Class ##
The script that will be using the dialog.
def RequestRoomNumber():
dialog = SampleEtoRoomNumberDialog();
rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
if (rc):
print dialog.GetText() #Print the Room Number from the dialog control
##########################################################################
Check to see if this file is being executed as the “main” python
script instead of being used as a module by some other python script
This allows us to use the module which ever way we want.
if name == “main”:
RequestRoomNumber()
你的代码有几个问题。
1:你的TextColor大小写写错了。self.m_label.TextColor
2:你没看懂帮助文档,这个属性可以读取和设置字体的颜色。需要的参数或返回的参数类型是Eto.Drawing.Color,所以直接给他这个类型的参数就行了。我看帮助文档也给了常用的颜色集合,所以就直接用了。
3:还有就是你这个写错了if name == “main”:
最后一点就是发帖贴代码没贴好,我Tab了好一会
#coding=utf-8
import Rhino
import scriptcontext
import System
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
T1 = "314"
class SampleEtoRoomNumberDialog(forms.Dialog[bool]):
# Dialog box Class initializer
def __init__(self):
# Initialize dialog box 初始化对话框
self.Title = '房间录入程序'
self.Padding = drawing.Padding(10)
self.Resizable = True
# Create controls for the dialog
self.m_label = forms.Label()
self.m_label.Text = '输入房间号:'
self.m_label.VerticalAlignment = forms.VerticalAlignment.Center
self.m_label.TextAlignment = forms.TextAlignment.Center
#设置颜色
self.m_label.TextColor = drawing.Colors.Red
self.m_textbox = forms.TextBox(Text = T1)
# Create the default button
self.DefaultButton = forms.Button(Text = '行')
self.DefaultButton.Click += self.OnOKButtonClick
# Create the abort button
self.AbortButton = forms.Button(Text = '退出')
self.AbortButton.Click += self.OnCloseButtonClick
# Create a table layout and add all the controls
layout = forms.DynamicLayout()
layout.Spacing = drawing.Size(5, 5)
layout.AddRow(self.m_label, self.m_textbox)
layout.AddRow(None) # spacer
layout.AddRow(self.DefaultButton, self.AbortButton)
# Set the dialog content
self.Content = layout
# Start of the class functions
# Get the value of the textbox
def GetText(self):
return self.m_textbox.Text
# Close button click handler
def OnCloseButtonClick(self, sender, e):
self.m_textbox.Text = ""
self.Close(False)
# OK button click handler
def OnOKButtonClick(self, sender, e):
if self.m_textbox.Text == "":
self.Close(False)
else:
self.Close(True)
## End of Dialog Class ##
def RequestRoomNumber():
dialog = SampleEtoRoomNumberDialog();
rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
if __name__ == "__main__":
RequestRoomNumber()