import tkinter as tk
import random
window = tk.Tk()
window.title(‘Random Name Picker’)
names = [‘Alice’, ‘Bob’, ‘Charlie’, ‘Dave’, ‘Eve’]
def pick_name():
# 从名字列表中随机挑选一个名字
name = random.choice(names)
# 更新标签的文本
label.config(text=name)
button = tk.Button(window, text=‘Pick a name’, command=pick_name)
button.pack()
label = tk.Label(window, text=’ ')
label.pack()
window.mainloop()
import tkinter as tk
import random
# 定义窗口
window = tk.Tk()
window.title('Random Name Picker')
# 定义名字列表
names = ['Alice', 'Bob', 'Charlie', 'Dave', 'Eve']
# 定义点名函数
def pick_name():
# 从名字列表中随机挑选一个名字
name = random.choice(names)
# 更新标签的文本
label.config(text=name)
# 创建一个按钮
button = tk.Button(window, text='Pick a name', command=pick_name)
button.pack()
# 创建一个标签,显示选择的名字
label = tk.Label(window, text=' ')
label.pack()
# 运行主事件循环
window.mainloop()