import tkinter as tk
from tkinter import messagebox
window = tk.Tk()
window.title("逻辑网")
window.geometry('400x180')
window.iconbitmap('../image/icon.ico')
var1 = tk.StringVar()
l = tk.Label(window, bg='#B0B0B0', font=('微软雅黑', 15), width=20, textvariable=var1)
l.pack()
def click_button():
try:
val = lb.get(lb.curselection())
var1.set(val)
except Exception as e:
e = '发现一个错误'
messagebox.showwarning(e, '没有选择任何条目')
b1 = tk.Button(window, text='获取当前选项', command=click_button)
b1.pack()
var2 = tk.StringVar()
var2.set(("C语言", "Python", "Java", "C++"))
lb = tk.Listbox(window, listvariable=var2)
items = ["C", "Java", "Python", "C#", "Golang", "Runby"]
for i in items:
lb.insert('end', i)
lb.insert(0, '编程学习')
lb.delete(4)
lb.pack()
window.mainloop()