作为的默认值
text
的选项
CTkLabel
是
"CTkLabel"
,因此将显示
文本
未给出选项。只是为了设置
text=""
如果您不想显示任何内容,可以覆盖默认值。
如果已选择所有名称,则要重新启动随机选择,需要清除
chosen_names
在从中随机选择之前
names
:
...
def button_callback():
# Create a list of names
names = ["Alice", "Bob", "Carol", "Dave", "Eve"]
# Check if all the values in the list have been selected
if len(chosen_names) == len(names):
# clear chosen_names to restart
chosen_names.clear()
# Randomly select a name from the list
name = random.choice(names)
# Check if the name has already been chosen
# or the same as the current one
while name in (chosen_names or [label.cget("text")]):
name = random.choice(names)
# Add the name to the list of chosen names
chosen_names.append(name)
# Update the label text
label.configure(text=name)
label.grid_remove()
...
# set text="" to override the default value "CTkLabel"
label = customtkinter.CTkLabel(app, text="")
...