我有一个运行良好的Python 脚本.我想要添加的唯一一件事是来自Messagebox.showinfo中的数组的随机输出.我试着创建数组并引用数组,方法是:随机 Select ("数组"),其中"数组是列表的变量.脚本运行得很好,只是没有像预期的那样从数组中提取项.有什么 idea 吗?还是我做错了?tkinter有随机生成器选项吗?
messagebox.showinfo("Totals", random.choice(random_message))
我有一个运行良好的Python 脚本.我想要添加的唯一一件事是来自Messagebox.showinfo中的数组的随机输出.我试着创建数组并引用数组,方法是:随机 Select ("数组"),其中"数组是列表的变量.脚本运行得很好,只是没有像预期的那样从数组中提取项.有什么 idea 吗?还是我做错了?tkinter有随机生成器选项吗?
messagebox.showinfo("Totals", random.choice(random_message))
我认为这段代码可能会有所帮助:
from tkinter import messagebox
import random
random_message = ['Variant 1', 'Variant 2', 'Variant 3']
messagebox.showinfo("Totals", random.choice(random_message))
请注意这些库是如何导入的--使用import random
而不是from random import *
.在random_message
列表中,您可以 Select 任何字符串.