简体   繁体   English

拖曳小部件列表? Tkinter的

[英]Shuffling list of widgets? Tkinter

Finally I have finished this damn thing! 终于我完成了该死的事情! Except for one issue. 除了一个问题。

I have a program quiz program created with tkinter that grabs a dictionary from a list inside a JSON file. 我有一个使用tkinter创建的程序测验程序,该程序从JSON文件中的列表中获取字典。 Now everything appears to be working fine, except for the shuffling of a list of buttons which remain in the same order (for example, if the answer button is in the far right side of the frame each consecutive questions answer will be in the far right side). 现在,除了按顺序排列的按钮列表改组之外,其他所有功能似乎都正常运行(例如,如果答案按钮在框架的最右边,则每个连续的问题答案将在最右边)侧)。

Now each time clickCorrect runs, it runs loadQuestion which configures dictionary values to 4 buttons which then get appended to a list(buttonList). 现在,每次clickCorrect运行时,它将运行loadQuestion,它将字典值配置为4个按钮,然后将其附加到列表(buttonList)上。 I then shuffle this list and pack the buttons by index (I assume that because they get shuffled each time the program loops each button will be have a different index and so shuffling the order of the buttons) but still the remain in the same order. 然后,我对该列表进行混排并按索引打包按钮(我假设因为每次程序循环时它们都会被混排,所以每个按钮将具有不同的索引,因此对按钮的顺序进行混排),但其余部分的顺序相同。 Is it the packing of the buttons that is causing this? 是按钮的包装导致了这一点吗? Or is random.shuffle() in the wrong position?? 还是random.shuffle()位置错误?

Essentially what I am asking is if packing values(buttons) from a list negating the random.shuffle() method? 本质上,我要问的是是否从列表中打包值(按钮),否定random.shuffle()方法?

You should shuffle the button list just after you've created it (where you have a comment saying # shuffle button list ). 创建按钮列表后,应立即对其进行洗牌(在其中带有# shuffle button list的注释)。 By the way, it would be just as easy to create the list by writing 顺便说一句,通过编写列表来创建列表同样容易

self.buttonList= [self.answerBtn, self.wrong1Btn,
                  self.wrong2Btn, self.wrong3Btn] 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM