简单tkinter使用
https://blog.csdn.net/qq_52480014/article/details/114264635
import tkinter as tk # Python 3 import
# import Tkinter as tk # Python 2 import
root = tk.Tk()
def my_function():
current_id = my_entry.get()
url_member = "https://api.example.com/member?member_id="+str(current_id)
print(url_member)
#do stuff with url_member
my_label = tk.Label(root, text = "Member ID# ")
my_label.grid(row = 0, column = 0)
my_entry = tk.Entry(root)
my_entry.grid(row = 0, column = 1)
my_button = tk.Button(root, text = "Submit", command = my_function)
my_button.grid(row = 1, column = 1)
root.mainloop()
#coding:utf-8
from tkinter import *
class App:
def __init__(self,root):
#定义帧
frame = Frame(root)
frame.pack()
self.frame = frame
w = Label(frame,text = "calculator")
w.pack()
self.newinput()
#调用回调函数
button1 = Button(frame,text='1',fg="red",command = lambda : self.buttoncb(1))
button1.pack()
button2 = Button(frame,text='2',fg="red",command = lambda : self.buttoncb(2))
button2.pack()
button = Button(frame,text='Quit',fg="red",command = root.quit)
button.pack()
def newinput(self):
v = StringVar()
e = Entry(self.frame,textvariable = v)
self.v = v
e.pack()
#定义回调函数
def buttoncb(self,i):
#print "button"
val = self.v.get()
self.v.set(val+str(i))
root=Tk()
a = App(root)
root.mainloop()
- 【list】选择,点击后关【闭并】获取list结果
import tkinter as tk # 使用Tkinter前需要先导入
window = tk.Tk()
window.title('城市选择')
window.geometry('500x300') # 设置窗口大小
window.resizable(0, 0) # 设置窗口宽高固定
tk.Label(window, text='出生的城市', font=('宋体', 10)).place(x=85, y=18, anchor='nw')
tk.Label(window, text='生活的城市', font=('宋体', 10)).place(x=85, y=88, anchor='nw')
tk.Label(window, text='上学的城市', font=('宋体', 10)).place(x=85, y=161, anchor='nw')
tk.Label(window, text='向往的城市', font=('宋体', 10)).place(x=85, y=230, anchor='nw')
var_1 = tk.StringVar()
var_1.set("请选择")
tk.OptionMenu(window,var_1, '北京','天津','石家庄','广州','杭州','南京','上海','深圳').place(x=200, y=15, anchor='nw')
var_2 = tk.StringVar()
var_2.set("请选择")
tk.OptionMenu(window,var_2, '北京','天津','石家庄','广州','杭州','南京','上海','深圳').place(x=200, y=80, anchor='nw')
var_3 = tk.StringVar()
var_3.set("请选择")
tk.OptionMenu(window,var_3, '北京','天津','石家庄','广州','杭州','南京','上海','深圳').place(x=200, y=152, anchor='nw')
var_4 = tk.StringVar()
var_4.set("请选择")
tk.OptionMenu(window,var_4, '北京','天津','石家庄','广州','杭州','南京','上海','深圳').place(x=200, y=220, anchor='nw')
on_hit = True
urs_t,urs_j,urs_q,urs_p = '','','',''
def getValue():
global on_hit,urs_t,urs_j,urs_q,urs_p
if on_hit == False:
on_hit = True
urs_t = var_1.get()
urs_j = var_2.get()
urs_q = var_3.get()
urs_p = var_4.get()
else:
on_hit = False
window.destroy()
return urs_t,urs_j,urs_q,urs_p
tk.Button(window,text='导出',width=15, pady=5, command=getValue).place(x=350, y=250, anchor='nw')
window.mainloop()