# -*- coding: utf-8 -*-
import sys
import tkinter.messagebox as box
from tkinter.filedialog import asksaveasfile
if sys.version_info[0] >= 3:
import tkinter as tk
import tkinter.ttk as ttk
else:
import Tkinter as tk
import sqlite3
from tkinter import *
class windowclass(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
master.title("綠建築查詢系統")
self.master.geometry("820x800")
self.dict = {}
self.dict1 = {}
self.lb1 = tk.Label(master,text='依指標選擇')
self.lb1.place(x=0,y=0)
self.lb2 = tk.Label(master,text='依屬性選擇')
self.lb2.place(x=200,y=0)
self.lb3 = tk.Label(master,text='依變數值選擇')
self.lb3.place(x=400,y=0)
# Initialize comboboxes
self.combobox_a = ttk.Combobox(master, values=list(self.dict.keys()), state='readonly')
self.combobox_b = ttk.Combobox(master, values=self.dict['CO2減量指標'], state='readonly')
self.combobox_c = ttk.Combobox(master, values=self.dict1['構造形式'], state='readonly')
# Select 0 element
self.combobox_a.current(0)
self.combobox_b.current(0)
self.combobox_c.current(0)
# Add event to update variables on combobox's value change event
self.combobox_a.bind("<<ComboboxSelected>>", lambda f1: self.fun())
self.combobox_b.bind("<<ComboboxSelected>>", lambda f2: self.fun2())
self.combobox_c.bind("<<ComboboxSelected>>", lambda f3: self.fun3())
# Initialize variables
self.area = self.combobox_a.get()
self.last_area = self.country = self.combobox_b.get()
self.last_country = self.twon = self.combobox_c.get()
# Place all controls to frame
self.combobox_a.place(x=0,y=25)
self.combobox_b.place(x=180,y=25)
self.combobox_c.place(x=360,y=25)
self.lb4 = tk.Label(master,text='已選擇條件')
self.lb4.place(x=0,y=60)
self.listb1 = tk.Listbox(master,width=100)
self.listb1.place(x=0,y=80)
self.lb5 = tk.Label(master,text='前次選擇條件')
self.lb5.place(x=0,y=260)
self.listb2 = tk.Listbox(master,width=100)
self.listb2.place(x=0,y=280)
def ok():
print (self.cb1_value.get())
print (self.cb2_value.get())
print (self.cb3_value.get())
self.btn = tk.Button(master , text = "加入" , command = ok )
self.btn.place(x=640,y=250)
self.btn1 = tk.Button(master , text = "查詢" , command =self.command)
self.btn1.place(x=640,y=450)
def fun(self):
print("changed 1-st combobox value to: " + self.combobox_a.get())
if self.last_area != self.combobox_a.get():
self.combobox_b['values']=self.dict[self.combobox_a.get()]
self.combobox_b.current(0)
self.country = self.combobox_b.get()
self.last_area = self.area = self.combobox_a.get()
def fun2(self):
print("changed 2-nd combobox value to: " + self.combobox_b.get())
if self.last_country != self.combobox_b.get():
self.combobox_c['values']=self.dict1[self.combobox_b.get()]
self.combobox_c.current(0)
self.twon = self.combobox_c.get()
self.last_country = self.country = self.combobox_b.get()
def fun3(self):
print("changed 3-rd combobox value to: " + self.combobox_c.get())
self.twon = self.combobox_c.get()
def command(self):
self.newWindow = tk.Toplevel(self.master)
class windowclass0(tk.Frame):
def __init__(self , master):
tk.Frame.__init__(self, master)
master.title("SUUMARY")
self.master.geometry("820x800")
self.quitButton2 = tk.Button(master, text = 'Quit', width = 25 , command = self.close_window2)
self.quitButton2.place(x=400,y=250)
self.frame2 = tk.Frame(master)
self.frame2.place(x=0, y=10, width=800, height=650)
#滚动条
self.scrollBar2 = Scrollbar(self.frame2)
self.scrollBar2.pack(side=RIGHT, fill=Y,)
self.scrollBar3 = Scrollbar(self.frame2,orient=HORIZONTAL)
self.scrollBar3.pack(side=BOTTOM, fill=X)
self.tree2 = ttk.Treeview(self.frame2,
columns=('c1','c2','c3','c4','c5','c6','c7','c8','c9','c10','c11','c12','c13','c14','c15'),
show="headings",
yscrollcommand=self.scrollBar2.set,
xscrollcommand=self.scrollBar3.set)
#设置每列宽度和对齐方式
self.tree2.column('c1', width=100, anchor='center')
self.tree2.column('c2', width=150, anchor='center')
self.tree2.column('c3', width=150, anchor='center')
self.tree2.column('c4', width=150, anchor='center')
self.tree2.column('c5', width=150, anchor='center')
self.tree2.column('c6', width=180, anchor='center')
self.tree2.column('c7', width=100, anchor='center')
self.tree2.column('c8', width=100, anchor='center')
self.tree2.column('c9', width=100, anchor='center')
self.tree2.column('c10', width=100, anchor='center')
self.tree2.column('c11', width=100, anchor='center')
self.tree2.column('c12', width=100, anchor='center')
self.tree2.column('c13', width=100, anchor='center')
self.tree2.column('c14', width=100, anchor='center')
self.tree2.column('c15', width=100, anchor='center')
#设置每列表头标题文本
self.tree2.heading('c1', text='編號')
self.tree2.heading('c2', text='外殼設計方案')
self.tree2.heading('c3', text='空調設計方案')
self.tree2.heading('c4', text='照明設計方案')
self.tree2.heading('c5', text='CO2減量方案')
self.tree2.heading('c6', text='廢棄物減量方案')
self.tree2.heading('c7', text='室內環境設計方案')
self.tree2.heading('c8', text='生物多樣性方案')
self.tree2.heading('c9', text='綠化量設計方案')
self.tree2.heading('c10', text='基地保水設計方案')
self.tree2.heading('c11', text='水資源節省方案')
self.tree2.heading('c12', text='污水垃圾改善方案')
self.tree2.heading('c13', text='總成本(元)')
self.tree2.heading('c14', text='單位成本(元/坪)')
self.tree2.heading('c15', text='單位成本(元/平方公尺)')
self.tree2.pack(side=LEFT, fill=Y)
#Treeview组件与垂直滚动条结合
self.scrollBar2.config(command=self.tree2.yview)
self.scrollBar3.config(command=self.tree2.xview)
#插入演示数据
conndb = sqlite3.connect("C:/data/outputnew.db")
c = conndb.cursor()
sql="""select * from '成本'"""
for r in c.execute(sql):
self.tree2.insert("","end",values=r)
def close_window2(self):
self.master.destroy()
class windowclass1(windowclass):
def __init__(self , master ):
self.master = master
self.frame = tk.Frame(master)
master.title("結果")
self.master.geometry("1000x500")
self.quitButton = tk.Button(master, text = 'Quit', width = 25 , command = self.close_window)
self.quitButton.place(x=400,y=250)
self.frame1 = tk.Frame(master)
self.frame1.place(x=0, y=10, width=800)
#滚动条
self.scrollBar = Scrollbar(self.frame1)
self.scrollBar.pack(side=RIGHT, fill=Y,)
self.scrollBar1 = Scrollbar(self.frame,orient=HORIZONTAL)
self.scrollBar1.pack(side=BOTTOM, fill=X)
self.tree = ttk.Treeview(self.frame1,
columns=('c1','c2','c3','c4','c5','c6','c7'),
show="headings",
yscrollcommand=self.scrollBar.set,
xscrollcommand=self.scrollBar1.set)
#设置每列宽度和对齐方式
self.tree.column('c1', width=100, anchor='center')
self.tree.column('c2', width=150, anchor='center')
self.tree.column('c3', width=150, anchor='center')
self.tree.column('c4', width=150, anchor='center')
self.tree.column('c5', width=150, anchor='center')
self.tree.column('c6', width=180, anchor='center')
self.tree.column('c7', width=100, anchor='center')
#设置每列表头标题文本
self.tree.heading('c1', text='方案')
self.tree.heading('c2', text='燈具系統')
self.tree.heading('c3', text='燈具效率係數(IER)')
self.tree.heading('c4', text='照明功率係數(IDR)')
self.tree.heading('c5', text='再生能源節能比例(%)')
self.tree.heading('c6', text='建築能源管理系統效率(Beta2)')
self.tree.heading('c7', text='指標得分')
self.tree.pack(side=LEFT, fill=Y)
#Treeview组件与垂直滚动条结合
self.scrollBar.config(command=self.tree.yview)
self.scrollBar1.config(command=self.tree.xview)
#插入演示数据
conndb = sqlite3.connect('C:/data/outputnew.db')
curr = conndb.cursor()
curr.execute('select * from "'+self.windowclass.self.combobox_a.get()+'" where "'+self.windowclass.self.combobox_b.get()+'" = "'+self.windowclass.self.combobox_c.get()+'"')
rows=curr.fetchall()
for row in rows:
self.tree.insert("","end",values=row)
def close_window(self):
self.master.destroy()
if __name__ == "__main__":
root = tk.Tk()
root2 = tk.Tk()
app=windowclass(root)
m=windowclass0(root2)
app.mainloop()