English 中文(简体)
如何每当 click点一个 but子时就这样做,就会把下一个线列入一个清单。
原标题:how can i make it so every time i click a button on tkinter, it outputs the next line on a list

我曾试图使一些小型项目让我开始在Tkinter上,我想制定一套规则,在你点击一个县时,它将下一个规则付诸实施。 请问一下如何做到这一点。

基本上,在我所知甚少的情况下,一经打上了差错的东西。 这是十条规则,试图列入一个清单,并利用职能执行每项规则。 不能像你能够告诉的那样真正地做事。

from tkinter import *

rules=Tk()
rules.title("Rules")
rules.geometry("200x200")

def click():
    rule_label1 = rule_label1(rules, text=("The rules are quite simple"))
    rule_label2 = rule_label2(rules, text=("You get to roll two dice. The total score of the dice is added onto your personal score so for example, if you roll a 5 and a 6, you would get 11"))
    rule_label3 = rule_label3(rules, text=("If the total that you get is an even number then excellent because you get an extra 10 points"))
    rule_label4 = rule_label4(rules, text=("Bad news if your total is an add number though because that is -5 points"))
    rule_label5 = rule_label5(rules, text=("Double rolls allow you to roll an extra dice which is also added onto your total"))
    rule_label6 = rule_label6(rules, text=("Scores cannot go below 0 at any point"))
    rule_label7 = rule_label7(rules, text=("There will be 5 rounds and the person whose total is the highest wins"))
    rule_label8 = rule_label8(rules, text=("In the rare case of a tie, a single dice roll will decide who wins overall"))
    rule_label9 = rule_label9(rules, text=("Enjoy!!!"))
    rule_label10 = rule_label10(rules, text=("You can now close this screen."))                      
    
button = Button(rules, text="Click for next line", font="calibri", padx=50, pady=50, command=click, fg="red", bg="Green")
button.pack()

rules.mainloop()

问题回答

致欢迎!

  1. 首先,将您的规则移至一份清单;请上表_texts

  2. 创建标签(rule_label),其中将显示案文,并将其首先输入名单(rule_texts[0])。

  3. 该指数将参照从<代码>_texts检索的索引。

  4. Define click() which set the rule_label to the ith index of rule_texts, 然后插入i by 1.

  5. (摘要) 在您到达<代码>末尾时添加处理程序,规则_text。

from tkinter import *

rules = Tk()
rules.title("Rules")
rules.geometry("1000x200")

rule_texts = [
    "The rules are quite simple",
    "You get to roll two dice. The total score of the dice is added onto your personal score so for example, if you roll a 5 and a 6, you would get 11",
    "If the total that you get is an even number then excellent because you get an extra 10 points",
    "Bad news if your total is an add number though because that is -5 points",
    "Double rolls allow you to roll an extra dice which is also added onto your total",
    "Scores cannot go below 0 at any point",
    "There will be 5 rounds and the person whose total is the highest wins",
    "In the rare case of a tie, a single dice roll will decide who wins overall",
    "Enjoy!!!",
    "You can now close this screen.",
]

rule_label = Label(
    rules,
    text=rule_texts[0],
    font="calibri",
    padx=50,
    pady=50,
    fg="black",
)
rule_label.pack()


i = 1


def click():
    global i
    rule_label.config(text=rule_texts[i])
    i += 1
    # if i == len(rule_texts):
        # button.config(state=DISABLED)
        # button.destroy()


button = Button(
    rules,
    text="Click for next line",
    font="calibri",
    padx=50,
    pady=50,
    command=click,
    fg="red",
    bg="Green",
)
button.pack()


rules.mainloop()




相关问题
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 ]="...

热门标签