程序效果如图。
代码如下。
# -*coding:UTF-8*-
from tkinter import Tk,Button,Label
import sys
def dui():dui=Tk()dui.title("自制对话框")lable=Label(dui,text='恭喜你,答对了!')lable.pack()button3=Button(dui,text='好',command=bye)button3.pack()dui.mainloop()
def bye():sys.exit()
def cuo():cuo=Tk()cuo.title("自制对话框")label1=Label(cuo,text='好抱歉,答错了,你是没用过Python吗?')label1.pack()button4=Button(cuo,text='好',command=bye)button4.pack()cuo.mainloop()
root=Tk()
root.title("自制对话框")
root.geometry("300x100")
theLabel = Label(root, text=' tkinter是哪个语言的库?',)
theLabel.pack()
button1=Button(root,text='Python', command=dui)
button1.pack()
button2=Button(root,text='Java', command=cuo)
button2.pack()
root.mainloop()