每次程序启动时应用随机函数(来自其中的两个)

2024-10-03 23:21:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我创建了两个函数来更改应用程序的主题。以下是一些例子:

def redtheme():
    text.config(background="light salmon", foreground="red",
            insertbackground="red")

def greentheme():
    text.config(background="pale green", foreground="dark green",
                insertbackground="dark green")

def bluetheme():
    text.config(background="light blue", foreground="dark blue",
                insertbackground="blue")

(text是文本小部件的名称)

我想创建一个函数,使这些函数中的任意一个在应用程序启动时运行。 换句话说,我想要一个在应用程序启动时执行的函数,该函数将从random.choice()中选择一个函数并执行该函数:

full = (redtheme, greentheme, bluetheme)
selected = random.choice(full)
# here, it could be text.config(full)?? or what?

如何使应用程序在启动时执行三个函数中的一个


Tags: 函数textconfig应用程序defgreenbluered