python中如何调用输入值_python – 在maya UI中调用用户输入值

编辑:像DrWeeny说的那样,最好参考其他类似的主题.

我前段时间在博客上做了一点提醒,以便能够测试所有不同的本机Maya UI使用命令的方式,并快速测试它们:

>经典玛雅弦

>作为参数的功能

> lambda

> functools.partial

> pymel.core.Callback

每个案例还给出了将变量作为参数传递给这些函数的示例.因为有时你必须能够.

总的来说,我完全推荐使用functools.partial,它只提供优于其他的优点(如果你忘记了PySide).

def function(*args):

print args

cmds.textFieldGrp(text, edit=True, text=str(args))

variable = 'Variable'

width = [1, 250]

align = [1, 'left']

window = cmds.window(title='UI and commands arguments.')

cmds.columnLayout()

cmds.textFieldGrp(label="\"function()\"", changeCommand="function()", columnWidth=width, columnAlign=align)

cmds.textFieldGrp(label="function", changeCommand=function, columnWidth=width, columnAlign=align)

cmds.textFieldGrp(label="\"function(variable)\"", changeCommand="function(variable)", columnWidth=width, columnAlign=align)

cmds.textFieldGrp(label="lambda x: function(variable)", changeCommand=lambda x: function(variable), columnWidth=width, columnAlign=align)

cmds.separator(style="double", height=20)

import functools

cmds.textFieldGrp(changeCommand=functools.partial(function), label='functools.partial(function)', columnWidth=width, columnAlign=align)

cmds.textFieldGrp(changeCommand=functools.partial(function, variable), label='functools.partial(function, variable)', columnWidth=width, columnAlign=align)

cmds.separator(style="single", height=20)

import pymel.core

cmds.textFieldGrp(changeCommand=pymel.core.Callback(function), label='pymel.core.Callback(function)', columnWidth=width, columnAlign=align)

cmds.textFieldGrp(changeCommand=pymel.core.CallbackWithArgs(function), label='pymel.core.CallbackWithArgs(function)', columnWidth=width, columnAlign=align)

cmds.textFieldGrp(changeCommand=pymel.core.CallbackWithArgs(function, variable), label='pymel.core.CallbackWithArgs(function, variable)', columnWidth=width, columnAlign=align)

cmds.separator(style="single", height=20)

text = cmds.textFieldGrp(label='RESULT: ', text='', width=500)

cmds.showWindow()

使用课程时

因为它不是在考虑课堂的情况下制作的,所以当你在课堂上时,某些方法根本不起作用.

class MayaUI():

def __init__(self):

self.variable = 'Variable'

self.width = [1, 250]

self.align = [1, 'left']

self.window = cmds.window(title='UI and commands arguments.')

cmds.columnLayout()

cmds.textFieldGrp(label="\"self.function()\"", changeCommand="self.function()", columnWidth=self.width, columnAlign=self.align)

cmds.textFieldGrp(label="self.function", changeCommand=self.function, columnWidth=self.width, columnAlign=self.align)

cmds.textFieldGrp(label="\"self.function(self.variable)\"", changeCommand="self.function(self.variable)", columnWidth=self.width, columnAlign=self.align)

cmds.textFieldGrp(label="lambda x: self.function(self.variable)", changeCommand=lambda x: self.function(self.variable), columnWidth=self.width, columnAlign=self.align)

cmds.separator(style="double", height=20)

import functools

cmds.textFieldGrp(changeCommand=functools.partial(self.function), label='functools.partial(self.function)', columnWidth=self.width, columnAlign=self.align)

cmds.textFieldGrp(changeCommand=functools.partial(self.function, self.variable), label='functools.partial(self.function, self.variable)', columnWidth=self.width, columnAlign=self.align)

cmds.separator(style="single", height=20)

import pymel.core

cmds.textFieldGrp(changeCommand=pymel.core.Callback(self.function), label='pymel.core.Callback(self.function)', columnWidth=self.width, columnAlign=self.align)

cmds.textFieldGrp(changeCommand=pymel.core.CallbackWithArgs(self.function), label='pymel.core.CallbackWithArgs(self.function)', columnWidth=self.width, columnAlign=self.align)

cmds.textFieldGrp(changeCommand=pymel.core.CallbackWithArgs(self.function, self.variable), label='pymel.core.CallbackWithArgs(self.function, self.variable)', columnWidth=self.width, columnAlign=self.align)

# A bit more complicated

_map = {'textFieldGrp': lambda arg:cmds.textFieldGrp(arg, query=True, text=True)}

_com = lambda *args:args[0](self.variable, _map[args[1]](args[2]))

cmds.textFieldGrp('textfieldName', changeCommand=pymel.core.Callback(_com, self.function, 'textFieldGrp', 'textfieldName'), label="pymel.core.Callback(_com, self.function, 'textFieldGrp', 'textfieldName') + lambdas", columnWidth=self.width, columnAlign=self.align)

cmds.separator(style="single", height=20)

self.text = cmds.textFieldGrp(label='RESULT: ', text='', width=500)

cmds.showWindow()

def function(self, *args):

print args

cmds.textFieldGrp(self.text, edit=True, text=str(args))

MayaUI()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值