English 中文(简体)
• 如何以沙捞法(ttk)和沙捞法(ttk)形成一个案文。
原标题:How to create a textevariable Label (ttk) with Python

页: 1

I aim to create a widget where the points of a word would appear. I created an entry, and I d like to display the points that the word is worth.

我的守则是:

这是创建<条码> Label的职能:

def create_variabletext_label2(root, col, row, val):
    val1 = IntVar()
    val1.set(m.comptabilisation_points(val.get()))

    # Here val is the value of the word input onto the entry widget
    # and m.comptabilisation_point() is a function that counts the
    # points of the word.
    label = Label(root, textvariable=val1)
    label.grid(column=col, row=row)
    return val1, label

这里的职能是:

def create_entry_string(root, width, col, row, columnspan, rowspan):
    val=StringVar()
    entry=ttk.Entry(root, width=width, textvariable=val)
    entry.grid(column=col, row=row, columnspan=columnspan, rowspan=rowspan)
    return val, entry

然后我称这些职能:

val_entry_mot, entry_mot = create_entry_string(root, 15, 1, 1, 1, 1)
val_points, label_points = create_variabletext_label2(root, 1, 2, val_entry_mot)

My problem is that the Label keeps displaying 0. The label doesn t change according the word s points.

Thank s for your help. MFF

担心含糊不清。

补充资料:

我试图制造一种摇欲坠的游戏。 实际上,我的问题是,我不知道如何显示值得一提的要点。 即使条目价值发生变化,标签也无变化。

首先,我想到<代码>val_enter_mot/code>的价值在变化。 因此,我只试图通过修改以下功能来显示投入的字句:create_variable_text2()

def create_variabletext_label2(root, col, row, val):
        label = Label(root, textvariable=val)
        label.grid(column=col, row=row)
        return val, label

它发挥了作用。 每当我改写入境口时,标签就显示这个词。

接着,我认为,应该算上字点的法典有缺陷。 这里是:

def comptabilisation_points(word):
    dico_values=values_scrabble()
    points=0
    for i in word.upper():
        points+=dico_values[i]
    return points

Values_scrabble(>> is a function that opens a file and transformation it into a dictionary = A: 1, C : 3, B : 3, E : 1, D : 2, G : 2, F : 4, I : 1, H : 4, K : 10, J : 8, M : 2, L : 1, O : 1, N : 1, Q : 8, P : 3, S : 1, R : 1, U : 1, T : 1, W : 10, V code: 4, Y: 10, X: 10, :

在我试图计算一个字眼点时,它实际上发挥了作用。 因此,我相信,我的问题是在这里。

这里是游戏的屏幕。 现在已经翻了一番,但你必须知道的是第一部<代码>。 顶端的“是,如果你对以下字句和直线表示意见,就应显示字数。

“Game

我希望我的发言是明确的。 谢谢。

MFF

问题回答

页: 1

In [1]: val_entry_mot.get()
Out[1]:   

因此,<代码>val1.set(>不能正常运作。

如果你直接确定这一点,你的法典将发挥作用,例如:

val1.set(123) # This properly renders "123" as Label text




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签