小编fin*_*oot的帖子

当`tk.Scale`的值发生变化时,如何自动更新`tk.Label`?

我放入了我的框架比例,但我不确定如何在我的标签中显示这个比例的值.我需要在每次比例移动时更新它.我怎样才能做到这一点?

self.options_settings.framepripojeni6 = Frame(self.options_settings.tab1)
        self.options_settings.framepripojeni6.pack(side=tkinter.TOP, expand=0, fill=tkinter.BOTH, padx=2, pady=4)

        self.options_settings.scale = Scale(self.options_settings.framepripojeni6,from_=1, to=60, length=350)
        self.options_settings.scale.pack(side=tkinter.TOP)

        self.options_settings.labelScale = tkinter.Label(self.options_settings.framepripojeni5, text="x")
        self.options_settings.labelScale.pack(side=tkinter.LEFT)
Run Code Online (Sandbox Code Playgroud)

python user-interface tkinter tkinter-scale

1
推荐指数
1
解决办法
1969
查看次数

是否可以将语句转换为表达式?

在C中,您可以在一行中分配两个变量

b = a = sqrt(10);
Run Code Online (Sandbox Code Playgroud)

在德尔福

b := a := Sqrt(10);
Run Code Online (Sandbox Code Playgroud)

不被允许.

有了Delphi中讨论IfThen三元运算符?:的"替代" - 相当于C#的三元运算符?总之,IfThen似乎并非绝对必要.

所以也许还有这样的东西:

function AssignAndReturn(var LHS: Integer; RHS: Integer): Integer;
begin
  LHS := RHS;
  Result := RHS;
end;

(...)

var
  a, b: Integer;
begin
  b := AssignAndReturn(a, Round(Sqrt(10)));
Run Code Online (Sandbox Code Playgroud)

我不是想"让一切看起来像C".我刚才注意到,有时再次在同一行中"重用"赋值的右侧会很好.(参见Lazarus/Free Pascal:如何改进while循环的编码风格(避免使用无限循环),例如,每次传递都会重新分配布尔表达式.)

delphi pascal freepascal lazarus turbo-pascal

1
推荐指数
1
解决办法
1156
查看次数

'__main__' 在 type() 的输出中是什么意思

如果我创建一个如下所示的类,并检查对象的类型,我会得到以下输出。

我的问题是__main__这里是什么意思?

class Student(object):
    pass

>>>a = Student()
>>>type(a)
<class '__main__.Student'>
Run Code Online (Sandbox Code Playgroud)

还有一个问题,如果我检查 Student 类的类型,我会得到以下输出。

>>>type(Student)
<class 'type'>
Run Code Online (Sandbox Code Playgroud)

<class 'type'>这里是什么意思?

python python-2.7 python-3.x

1
推荐指数
1
解决办法
1768
查看次数

Python SymPy解决线性系统

我有Python 3.3.3和SymPy 0.7.4.1,都是x64版本,并在我的计算机上本地安装.我正在使用PSPad作为Python脚本编写的配置编辑器.

sympy在模块中使用库中的导入时,应该求解一组三个线性方程:

from sympy import Matrix, solve_linear_system
from sympy.abc import x, y, z

def main():
    system = Matrix (((3,2,-1,1) ,(2,-2,4,-2),(-1,0.5,-1,0)))
    print(solve_linear_system(system, x, y,z))

if __name__ == "__main__":
    main()
Run Code Online (Sandbox Code Playgroud)

编辑器PSPad控制台输出返回以下内容:

traceback (most recent call last):   File "C:\Users\GOODLU~1\AppData\Local\Temp\PSpad\securesafety_DISK_5GB\Programmation\linear system solve SYMPY.py", line 1, in <module>
    from sympy import Matrix,solve_linear_system   File "C:\Users\GOODLU~1\AppData\Local\Temp\PSpad\securesafety_DISK_5GB\Programmation\sympy.py", line 2, in <module>
    from sympy import var,Eq,solve ImportError: cannot import name var

Process completed, Exit Code 1.
Execution time: 00:00.134
Run Code Online (Sandbox Code Playgroud)

实际上,我对这些问题非常怀疑:

  1. 为什么,当键入相同的东西,没有对象def main(),并在IDLE中逐行输入时,一切都正确解决,如:{x: 1.00000000000000, …

python sympy importerror

0
推荐指数
1
解决办法
904
查看次数

Python 代码与 if 的比较验证 False 当它应该是 True 时

我在下面有以下 Python 代码。我期待代码返回,True但是当我运行它时,它似乎总是返回False. 检查 361 是否为 361 时似乎失败,但我不知道为什么:

def comp(array1, array2):
    if array1 is None or array2 is None or len(array1) is 0 or len(array2) is 0 or len(array1) is not len(array2):
        return False

    aListSquared = [x * x for x in sorted(array1)]
    array2.sort()

    print(aListSquared)
    print(array2)

    for x in range(len(aListSquared)):
        print('{0}:{1}'.format(aListSquared[x], type(aListSquared[x])))
        print('{0}:{1}'.format(array2[x], type(array2[x])))

        if int(aListSquared[x]) is not int(array2[x]):
            return False

    return True


a1 = [121, 144, 19, 161, 19, 144, 19, 11]
a2 = [11 …
Run Code Online (Sandbox Code Playgroud)

python integer comparison-operators

0
推荐指数
1
解决办法
88
查看次数

IndentationError 在 `ast.parse` 和 `ast.walk` 的一个函数中,该函数是类中的一个方法

我想我知道IndentationError 中IndentationError描述的类似的常见原因:例如,unindent 不匹配任何外部缩进级别。这不适用于这里。

另外,我知道,textwrap.dedent但感觉这里不是正确的方法?


如果我有一个“正规”的功能,我可以做ast.parseast.walk这样的:

import ast
import inspect

def a():
    pass

code = inspect.getsource(a)
nodes = ast.walk(ast.parse(code))
for node in nodes:
    ...
Run Code Online (Sandbox Code Playgroud)

但是,如果函数是类中的方法,例如:

class B:
    def c(self):
        pass

code = inspect.getsource(B.c)
nodes = ast.walk(ast.parse(code))
Run Code Online (Sandbox Code Playgroud)

我得到:

IndentationError: unexpected indent
Run Code Online (Sandbox Code Playgroud)

我想这是有道理的,因为B.c 缩进了一级。那么我ast.parseast.walk这里怎么办呢?

python parsing indentation abstract-syntax-tree static-code-analysis

-1
推荐指数
1
解决办法
684
查看次数