最终结果
下拉选择合适的单位类型,输入数值和单位,自送转换计算,最终结果如下:
代码全部
import tkinter as tk
from tkinter import ttk
'''选择类型,触发事件内容为后面单位为对应的单位'''
def choose_unit(envet):
choose = box1.get()
list=[]
print(choose)
if choose == '体积':
list = ['立方厘米','立方米']
elif choose == '长度':
list = ['厘米', '分米', '米', '千米', '毫米']
elif choose == '面积':
list = ['平方厘米','平方米', '公顷']
box2['value'] = list
box3['value'] = list
'''选择单位后的触发事件,计算的结果出现在如下情况:选择了正确的单位,或者输入数字后回车'''
def convert(envet):
global data
global data_out
unit_class = box1.get()
if unit_class == '体积':
data_out.set(convert_V(data, box2.get(),box3.get()))
elif unit_class =='长度':
data_out.