python query oracle database
oracle sql script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | drop table IF EXISTS GEOVINDU.School; create table GEOVINDU.School --創建表 ( SchoolId char (5) NOT NULL , -- SchoolName varchar (500) NOT NULL , SchoolTelNo varchar (8) NULL , PRIMARY KEY (SchoolId) --#主鍵 ); --对表的说明 comment on table GEOVINDU.School is '学校表' ; --对表中列的说明 comment on column GEOVINDU.School.SchoolId is 'ID' ; comment on column GEOVINDU.School.SchoolName is '名称' ; comment on column GEOVINDU.School.SchoolTelNo is '电话号码' ; select * from GEOVINDU.School order by SchoolId; |
代码自己写的生成器生成。
MODEL:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | # encoding: utf-8 # 版权所有 2024 ©涂聚文有限公司 # 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎 # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 3.11 # OS : windows 10 # database : mysql 9.0 sql server 2019, poostgreSQL 17.0 oracle 11g # Datetime : 2024-11-20 14:35:21 # database :sql server 2019 # User : geovindu # Product : PyCharm # Project : IctGame # File : model/School.py # explain : 学习 class SchoolInfo( object ): """ 学校表 """ def __init__( self ): """ 構造 """ self ._SchoolId = None """ ID,主键 """ self ._SchoolName = None """ 校名 """ self ._SchoolTelNo = None """ 学校电话 """ @property def SchoolId( self ): """ ID,主键 """ return self ._SchoolId @SchoolId .setter def SchoolId( self , schoolId): """ ID,主键 :param SchoolId: :return: """ self ._SchoolId = schoolId @property def SchoolName( self ): """ 校名 """ return self ._SchoolName @SchoolName .setter def SchoolName( self , schoolName): """ 校名 :param SchoolName: :return: """ self ._SchoolName = schoolName @property def SchoolTelNo( self ): """ 学校电话 """ return self ._SchoolTelNo @SchoolTelNo .setter def SchoolTelNo( self , schoolTelNo): """ 学校电话 :param SchoolTelNo: :return: """ self ._SchoolTelNo = schoolTelNo |
IDAL:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | # encoding: utf-8 # 版权所有 2024 ©涂聚文有限公司 # 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎 # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 3.11 # OS : windows 10 # database : mysql 9.0 sql server 2019, poostgreSQL 17.0 oracle 11g # Datetime : 2024-11-20 14:35:21 # database :sql server 2019 # User : geovindu # Product : PyCharm # Project : IctGame # File : interface/School.py # explain : 学习 from __future__ import annotations from abc import ABC, abstractmethod import os import sys from model.school import SchoolInfo class ISchool(ABC): """ 学校表 """ @classmethod def __subclasshook__( cls , subclass): return ( hasattr (subclass, 'load_data_source' ) and callable (subclass.load_data_source) and hasattr (subclass, 'extract_text' ) and callable (subclass.extract_text) or NotImplemented) @abstractmethod def selectSql( cls ) - > list : """ :return: """ pass @abstractmethod def selectSqlCount( cls ) - > list : """ 查询数据 总数 :return: """ pass @abstractmethod def selectSqlOrder( cls , order: str ) - > list : """ :param order: :return: """ pass @abstractmethod def selectSort( cls ,field: str ,isOrder: bool ) - > list : """ :param field :param order: desc/asc :return: """ pass @abstractmethod def selectIdSql( cls , schoolId: str ): """ :param SchoolId: :return: """ pass @abstractmethod def selectProc( cls ): """ :return: """ pass @abstractmethod def selectIdProc( cls , schoolId): """ :param SchoolId: :return: """ pass @abstractmethod def addSql( cls , info: SchoolInfo): """ :param info: :return: """ pass @abstractmethod def addProc( cls , info: SchoolInfo): """ :param info: :return: """ pass @abstractmethod def addOutProc( cls , info: SchoolInfo): """ :param info: :return: """ pass @abstractmethod def editSql( cls , info: SchoolInfo): """ :param info: :return: """ pass @abstractmethod def editProc( cls , info: SchoolInfo): """ :param info: :return: """ pass @abstractmethod def delSql( cls , schoolId): """ :param SchoolId: :return: """ pass @abstractmethod def delProc( cls , schoolId): """ :param SchoolId: :return: """ pass |
DAL:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | # encoding: utf-8 # 版权所有 2024 ©涂聚文有限公司 # 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎 # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 3.11 # OS : windows 10 # database : mysql 9.0 sql server 2019, poostgreSQL 17.0 oracle 11g # Datetime : 2024-11-20 14:35:21 # database :sql server 2019 # User : geovindu # Product : PyCharm # Project : IctGame # File : dal/School.py # explain : 学习 from __future__ import annotations from abc import ABC, abstractmethod import os import sys from model.school import SchoolInfo from DBUtility.oracleHelper import OracleHelper from interface.school import ISchool class SchoolDal(ISchool): """ 学校表 """ myms = OracleHelper() def __init__( self ): """ 构造函数,方法 :param strserver: :param struser: :param strpwd: :param strdatabase: """ self ._strserver = "" self ._struser = "" self ._strpwd = "" self ._strdatabase = "" def selectSql( cls ) - > list : """ 查询数据 self._strserver, self._struser, self._strpwd, self._strdatabase :return: """ row = cls .myms.execute( "select * from School" ) #cls.myms.close() return row def selectSqlCount( cls ) - > list : """ 查询数据 总数 :return: """ row = cls .myms.execute( "select count(*) as total from School" ) #cls.myms.close() return row[ 0 ] def selectSqlOrder( cls ,order: str ) - > list : """ :param order: SchoolId desc/asc :return: """ students = [] strsql = f "select * from School order by {order}" row = cls .myms.execute(f "select * from School order by {order}" ) return row def selectSort( cls ,field: str ,isOrder: bool ) - > list : """ :param field SchoolId :param order: desc/asc :return: """ order = 'desc' if isOrder = = True : order = 'desc' else : order = 'asc' strsql = f "select * from School order by {field} {order}" row = cls .myms.execute(f "select * from School order by {field} {order}" ) #cls.myms.close() return row def selectIdSql( cls ,schoolId: str ) - > list : """ :param SchoolId: 主键ID :return: """ row = cls .myms.execute(f "select * from School where SchoolId=schoolId" ) #考虑数据类型 #cls.myms.close() return row def selectProc( cls ) - > list : """ 存储过程 :return: """ args = () row = cls .myms.executeCallProc( "procSelectSchoolAll" ,args) return row def selectIdProc( cls ,SchoolId: str ) - > list : """ 存储过程 :param SchoolId: 主键ID :return: """ args = (SchoolId,) row = cls .myms.executeCallProc( 'procSelectSchool' , args) return row def addSql( cls ,info:SchoolInfo) - > int : """ 添加,要考虑添加返回ID值 :param info:实体类 :return: """ column = ( "SchoolId" , "SchoolName" , "SchoolTelNo" ) vales = [info.SchoolId,info.SchoolName,info.SchoolTelNo] return cls .myms.insertByColumnaAndValues( "School" ,column,vales) def addProc( cls ,info:SchoolInfo) - > int : """ 添加,要考虑添加返回ID值 :param info:实体类 :return: """ args = [info.SchoolId,info.SchoolName,info.SchoolTelNo] return cls .myms.insertCallProc( "procInsertSchool" ,args) def addOutProc( cls ,info:SchoolInfo) - > int : """ 添加,要考虑添加返回ID值 :param info:实体类 :return: 返回增加的ID """ id = 0 try : outSchoolId = ( 'char' ,) #输出,元组类型 考虑数据类型去转换 print (info) args = [info.SchoolName,info.SchoolTelNo,outSchoolId] print (args) result = cls .myms.insertOutCallProc( "procInsertSchoolOutput" , args) print (result) id = result except Exception as ex: print (ex) return id def editSql( cls ,info:SchoolInfo) - > int : """ :param info:实体类 :return: """ args = { "SchoolId" :f "{info.SchoolId}" , "SchoolName" :f "{info.SchoolName}" , "SchoolTelNo" :f "{info.SchoolTelNo}" } where = f "SchoolId={info.SchoolId}" # #print(args,where) return cls .myms.updateByKeyValues( "School" ,where,args) def editProc( cls , info: SchoolInfo) - > int : """ :param info: 实体类 :return: """ args = [info.SchoolId,info.SchoolName,info.SchoolTelNo] return cls .myms.updateProc( "procUpdateSchool" ,args) def delSql( cls ,SchoolId: str ) - > int : """ sql语句删除 :param SchoolId: 主键ID :return: """ where = {f "SchoolId" :SchoolId} return cls .myms.deleteByKeyValues( "School" ,where) def delProc( cls , SchoolId: str ) - > int : """ 删除 存储过程 删除多个ID,后面增加 :param SchoolId: 主键ID :return: """ args = SchoolId k = cls .myms.deleteProc( "procDuDeleteSchool" , args) return k |
BLL:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | # encoding: utf-8 # 版权所有 2024 ©涂聚文有限公司 # 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎 # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 3.11 # OS : windows 10 # database : mysql 9.0 sql server 2019, poostgreSQL 17.0 oracle 11g # Datetime : 2024-11-20 14:35:21 # database :sql server 2019 # User : geovindu # Product : PyCharm # Project : IctGame # File : bll/School.py # explain : 学习 from __future__ import annotations from abc import ABC, abstractmethod import os import sys from model.school import SchoolInfo from factory.AbstractFactory import AbstractFactory class SchoolBll( object ): """ 学校表 """ dal = AbstractFactory.createSchool """ 类属性 接口DAL """ def __init__( self ): """ """ self .__name = "SchoolBll" def __del__( self ): print (f "{self.__name} ERASE MEMORY" ) def selectData( self ) - > list : """ :return: """ data = self .dal().selectSql() return data def select( self ) - > list [SchoolInfo]: """ :return: """ schools = [] data = self .dal().selectSql() if len (data) > 0 : for SchoolId,SchoolName,SchoolTelNo in data[ 0 ]: info = SchoolInfo() info.SchoolId = SchoolId info.SchoolName = SchoolName info.SchoolTelNo = SchoolTelNo schools.append(info) return schools def selectSql( cls ) - > list [SchoolInfo]: """ 元组数据 :return: list 列表 """ schools = [] data = cls .dal().selectSql() if len (data) > 0 : for SchoolId,SchoolName,SchoolTelNo in data[ 0 ]: info = SchoolInfo() info.SchoolId = SchoolId info.SchoolName = SchoolName info.SchoolTelNo = SchoolTelNo schools.append(info) return schools def selectSqlCount( cls ) - > int : """ 查询数据 总数 :return: """ #print(cls.dal().selectSqlCount()[0][0]) total = cls .dal().selectSqlCount()[ 0 ][ 0 ] return total def Count( self ) - > int : """ 查询数据 总数 :return: """ total = self .dal().selectSqlCount()[ 0 ][ 0 ] return total def selectSqlOrder( cls , order: str ) - > list [SchoolInfo]: """ 元组数据 :param order: SchoolName desc/asc :return: """ schools = [] data = cls .dal().selectSqlOrder(order) if len (data) > 0 : for SchoolId,SchoolName,SchoolTelNo in data[ 0 ]: info = SchoolInfo() info.SchoolId = SchoolId info.SchoolName = SchoolName info.SchoolTelNo = SchoolTelNo schools.append(info) return schools def selectSort( cls ,field: str ,isOrder: bool ) - > list [SchoolInfo]: """ :param field SchoolId :param order: desc/asc :return: """ schools = [] data = cls .dal().selectSort(field,isOrder) if len (data) > 0 : for SchoolId,SchoolName,SchoolTelNo in data[ 0 ]: info = SchoolInfo() info.SchoolId = SchoolId info.SchoolName = SchoolName info.SchoolTelNo = SchoolTelNo schools.append(info) return schools def selectIdSql( cls ,SchoolId: str ) - > list [SchoolInfo]: """ :param SchoolId:ID :return: """ schools = [] data = cls .dal().selectIdSql(SchoolId) #print(data) if len (data)> 0 : for SchoolId,SchoolName,SchoolTelNo in data[ 0 ]: info = SchoolInfo() info.SchoolId = SchoolId info.SchoolName = SchoolName info.SchoolTelNo = SchoolTelNo schools.append(info) return schools def selectProc( cls ) - > list [SchoolInfo]: """ :return: """ schools = [] data = cls .dal().selectProc() #print(data) if len (data) > 0 : for SchoolId,SchoolName,SchoolTelNo in data: info = SchoolInfo() info.SchoolId = SchoolId info.SchoolName = SchoolName info.SchoolTelNo = SchoolTelNo schools.append(info) return schools def selectIdProc( cls ,SchoolId: str ) - > list [SchoolInfo]: """ :param SchoolId: :return: """ schools = [] data = cls .dal().selectIdProc(SchoolId) if len (data) > 0 : for SchoolId,SchoolName,SchoolTelNo in data: info = SchoolInfo() info.SchoolId = SchoolId info.SchoolName = SchoolName info.SchoolTelNo = SchoolTelNo schools.append(info) return schools def addSql( cls ,info:SchoolInfo) - > int : """ :param info:实体类 :return: """ return cls .dal().addSql(info) def add( self ,info:SchoolInfo) - > int : """ :param info:实体类 :return: """ return self .dal().addSql(info) def addProc( cls ,info:SchoolInfo) - > int : """ :param info:实体类 :return: """ #print(info) return cls .dal().addProc(info) def addOutProc( cls ,info:SchoolInfo) - > int : """ :param info: 实体类 :return: 返回增加的ID """ print (info) return cls .dal().addOutProc(info) def editSql( cls ,info:SchoolInfo) - > int : """ :param info:实体类 :return: """ #print(info) return cls .dal().editSql(info) def edit( self ,info:SchoolInfo) - > int : """ :param info:实体类 :return: """ #print(info) return self .dal().editSql(info) def editProc( cls , info: SchoolInfo) - > int : """ :param info:实体类 :return: """ return cls .dal().editProc(info) def delSql( cls , SchoolId: str ) - > int : """ :param SchoolId: :return: """ return cls .dal().delSql(SchoolId) def delinfo( self , SchoolId: str ) - > int : """ :param SchoolId: :return: """ return self .dal().delSql(SchoolId) def delProc( cls , SchoolId: str ) - > int : """ :param SchoolId: :return: """ return cls .dal().delProc(SchoolId) |
gui:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | # encoding: utf-8 # 版权所有 2024 ©涂聚文有限公司 # 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎 # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 3.11 # OS : windows 10 # database : mysql 9.0 sql server 2019, poostgreSQL 17.0 oracle 11g # Datetime : 2024/12/24 20:28 # User : geovindu # Product : PyCharm # Project : pyOracleDemo # File : main.py # explain : 学习 import bll from bll.school import SchoolBll from model.school import SchoolInfo import ttkbootstrap as ttk from ttkbootstrap.constants import * from ttkbootstrap.tableview import Tableview class MainWidnow(ttk.Window): """ """ def __init__( self ): """ """ super ().__init__(themename = "cosmo" , title = "塗聚文學習進行中" ) # self.Window(themename="cosmo") #superhero self .maxsize = 300 # self.geometry('{}x{}'.format(1350, 900)) self .first_var = ttk.Variable() self .title = "main" self .themename = 'superhero' self .last_var = ttk.Variable() self .occupation_var = ttk.Variable() self .colors = self .style.colors self .coldata = [ { "text" : "编号" , "stretch" : False }, "名称" , { "text" : "电话" , "stretch" : False }, ] bl = bll.SchoolBll() infos = bl.selectSql() self .rowdata = [] for info in infos: row = [] row.append(info.SchoolId) row.append(info.SchoolName) row.append(info.SchoolTelNo) self .rowdata.append(row) self .dt = Tableview( master = self , coldata = self .coldata, rowdata = self .rowdata, paginated = True , pagesize = 15 , searchable = True , bootstyle = PRIMARY, stripecolor = ( self .colors.light, None ), ) self .dt.pack(fill = BOTH, expand = YES, padx = 10 , pady = 10 ) # dt.hide_selected_column(cid=0) #隱藏第一列 self .dt.view.bind( "<Double-1>" , self .rowselected) # dt.view.bind("<<TreeviewSelect>>", rowselected) b1 = ttk.Button( self , text = "Open" , bootstyle = "success" ) # ,command=self.openwindows b1.pack(side = LEFT, padx = 5 , pady = 10 ) # b1.bind("<Double-1>",openwindows) b1.bind( "<Button-1>" , self .openwindows) b2 = ttk.Button( self , text = "New" , bootstyle = "info-outline" ) b2.pack(side = LEFT, padx = 5 , pady = 10 ) def rowselected( self , event) - > None : try : iid = self .dt.view.selection()[ 0 ] # print(iid) values = self .dt.view.item(iid, 'values' ) self .first_var. set (values[ 0 ]) self .last_var. set (values[ 1 ]) self .occupation_var. set (values[ 2 ]) print (values[ 0 ], values[ 1 ], values[ 2 ]) data = [values[ 0 ], values[ 1 ], values[ 2 ]] subwindow = ChildNewWindow(data) except IndexError as err: pass def openwindows( self , event): """ """ try : print ( 'open windows' ) iid = self .dt.view.selection()[ 0 ] values = self .dt.view.item(iid, 'values' ) data = [values[ 0 ], values[ 1 ], values[ 2 ]] subwindow = ChildNewWindow(data) self .update() except IndexError as err: pass class ChildNewWindow(ttk.Window): """ 彈出子窗口 ttk.Toplevel """ def __init__( self , data): """ :param master: """ super ().__init__(title = 'Child Window' ) self .geometry( '{}x{}' . format ( 850 , 900 )) self .title = 'Child Window' self .label = ttk.Label( self , text = data[ 0 ]) self .label.pack() self .labe2 = ttk.Label( self , text = data[ 1 ]) self .labe2.pack() self .labe3 = ttk.Label( self , text = data[ 2 ]) self .labe3.pack() if __name__ = = '__main__' : print ( 'PyCharm' ) mainwindow = MainWidnow() mainwindow.mainloop() bl = bll.SchoolBll() infos = bl.selectSql() for info in infos: print (info.SchoolId,info.SchoolName,info.SchoolTelNo) |
输出:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | # encoding: utf-8 # 版权所有 2024 ©涂聚文有限公司 # 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎 # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 3.11 # OS : windows 10 # Datetime : 2024/11/29 20:48 # User : geovindu # Product : PyCharm # Project : pytestdemo # File : MainWidnow.py # explain : 学习 import ttkbootstrap as ttk from ttkbootstrap.constants import * from ttkbootstrap.tableview import Tableview from gui.mainwindow.childNewWindow import ChildNewWindow from gui.mainwindow.tabWindow import TabWindow import threading import pystray #pip install pystray from PIL import Image from pystray import MenuItem, Menu ''' https://ttkbootstrap.readthedocs.io/en/latest/themes/light/ https://ttkbootstrap.readthedocs.io/en/latest/themes/dark/ https://ttkbootstrap.readthedocs.io/en/latest/zh/api/tableview/tableview/ https://ttkbootstrap.readthedocs.io/en/latest/styleguide/entry/ https://docs.pysimplegui.com/en/latest/documentation/module/extending/event_bindings/ https://python-course.eu/tkinter/events-and-binds-in-tkinter.php cerulean cosmo cyborg darkly flatly journal litera lumen lux materia minty morph pulse quartz sandstone simplex sketchy sketchy solar spacelab superhero united vapor vapor zephyr ''' class MainWidnow(ttk.Window): """ """ def __init__( self ): """ """ super ().__init__(themename = "cosmo" , title = "Database Generator" ) # self.Window(themename="cosmo") #superhero self .maxsize = 500 # self.geometry('{}x{}'.format(1350, 900)) self .firstvar = ttk.Variable() #self.themename = 'superhero' self .iconbitmap( 'favicon.ico' ) # create a menubar menubar = ttk.Menu( self ) self .config(menu = menubar) # create the file_menu filemenu = ttk.Menu( menubar, tearoff = 0 ) # add menu items to the File menu filemenu.add_command(label = 'New' ,command = self .opengenerator) filemenu.add_command(label = 'Open...' ,command = self .opengenerator) filemenu.add_command(label = 'Close' ,command = self .opengenerator) filemenu.add_separator() # add a submenu submenu = ttk.Menu(filemenu, tearoff = 0 ) submenu.add_command(label = 'Keyboard Shortcuts' ,command = self .opengenerator) submenu.add_command(label = 'Color Themes' ,command = self .opengenerator) # add the File menu to the menubar filemenu.add_cascade( label = "Preferences" , menu = submenu ) # add Exit menu item filemenu.add_separator() filemenu.add_command( label = 'Exit' , command = self .destroy ) menubar.add_cascade( label = "Generator" , menu = filemenu, underline = 0 ) # create the Help menu helpmenu = ttk.Menu( menubar, tearoff = 0 ) helpmenu.add_command(label = 'Welcome' ) helpmenu.add_command(label = 'About...' ) # add the Help menu to the menubar menubar.add_cascade( label = "Help" , menu = helpmenu, underline = 0 ) self .lastvar = ttk.Variable() self .occupationvar = ttk.Variable() self .colors = self .style.colors self .coldata = [ { "text" : "LicenseNumber" , "stretch" : False }, "CompanyName" , { "text" : "UserCount" , "stretch" : False }, ] self .rowdata = [ ( 'A100' , '深圳市分公司' , 120 ), ( 'A101' , '廣州市分公司.' , 145 ), ( 'A102' , '東莞市分公司.' , 136 ), ( 'A103' , '惠州市分公司' , 112 ), ( 'A104' , '徽州市分公司.' , 245 ), ( 'A105' , '佛山市分公司.' , 236 ), ( 'A106' , '陽江市分公司' , 212 ), ( 'A107' , '江門市分公司.' , 345 ), ( 'A108' , '中山市分公司.' , 336 ), ( 'A109' , '河源市分公司' , 312 ), ( 'A110' , '贛州市分公司.' , 445 ), ( 'A111' , '湖州市分公司.' , 436 ), ( 'A112' , '抚州市分公司' , 412 ), ( 'A113' , '南昌市分公司.' , 545 ), ( 'A114' , '饒州市分公司.' , 536 ), ( 'A115' , '吉州市分公司' , 512 ), ( 'A116' , '濟州市分公司' , 645 ), ( 'A117' , '冀州市分公司.' , 636 ), ( 'A118' , '薊州市分公司' , 612 ), ( 'A119' , '雷州市分公司.' , 745 ), ( 'A120' , '台州市分公司.' , 736 ), ( 'A121' , '泰州市分公司' , 712 ), ( 'A122' , '南京市分公司.' , 845 ), ( 'A123' , '常州市分公司.' , 836 ), ( 'A124' , '青州市分公司' , 812 ), ( 'A125' , '德州市分公司.' , 945 ), ( 'A126' , '幽州市分公司.' , 36 ), ( 'A127' , '杭州市分公司' , 912 ), ( 'A128' , '溫州市分公司.' , 945 ), ( 'A129' , '泉州市分公司' , 1036 ), ( 'A130' , '文州市分公司' , 1012 ), ( 'A131' , '海州市分公司.' , 1045 ), ( 'A132' , '儋州市分公司.' , 1136 ), ( 'A133' , '江州市分公司' , 1112 ), ( 'A134' , '上海市分公司.' , 1145 ), ( 'A135' , '北京市分公司.' , 1136 )] self .dt = Tableview( master = self , coldata = self .coldata, rowdata = self .rowdata, paginated = True , pagesize = 15 , searchable = True , bootstyle = PRIMARY, stripecolor = ( self .colors.light, None ), ) self .dt.pack(fill = BOTH, expand = YES, padx = 10 , pady = 10 ) # dt.hide_selected_column(cid=0) #隱藏第一列 self .dt.view.bind( "<Double-1>" , self .rowselected) # dt.view.bind("<<TreeviewSelect>>", rowselected) b1 = ttk.Button( self , text = "生成" , bootstyle = "success" ) # ,command=self.openwindows b1.pack(side = LEFT, padx = 5 , pady = 10 ) # b1.bind("<Double-1>",openwindows) b1.bind( "<Button-1>" , self .openwindows) b2 = ttk.Button( self , text = "New" , bootstyle = "info-outline" ) b2.pack(side = LEFT, padx = 5 , pady = 10 ) b2.bind( "<Button-1>" , self .openlint) # 系统托盘图标 menu = (MenuItem( '显示1' , self .show_window, default = True ), Menu.SEPARATOR, MenuItem( '退出1' , self .quit_window)) image = Image. open ( "image/1.png" ) icon = pystray.Icon( "icon" , image, "pytestdemo" , menu) # 重新定义点击关闭按钮的处理 self .protocol( 'WM_DELETE_WINDOW' , self .on_exit) threading.Thread(target = icon.run, daemon = True ).start() def rowselected( self , event) - > None : try : iid = self .dt.view.selection()[ 0 ] # print(iid) values = self .dt.view.item(iid, 'values' ) self .firstvar. set (values[ 0 ]) self .lastvar. set (values[ 1 ]) self .occupationvar. set (values[ 2 ]) print (values[ 0 ], values[ 1 ], values[ 2 ]) data = [values[ 0 ], values[ 1 ], values[ 2 ]] subwindow = ChildNewWindow(data) except IndexError as err: pass def openwindows( self , event): """ """ try : print ( 'open windows' ) iid = self .dt.view.selection()[ 0 ] values = self .dt.view.item(iid, 'values' ) data = [values[ 0 ], values[ 1 ], values[ 2 ]] subwindow = ChildNewWindow(data) self .update() except IndexError as err: pass def opengenerator( self ): """ :return: """ print ( "link" ) suwindow = TabWindow() self .update() def openlint( self ,event): """ :param event: :return: """ #self.destroy() print ( "link" ) suwindow = TabWindow() self .update() def quit_window( self ,icon: pystray.Icon): """ :param icon: :return: """ icon.stop() self .destroy() def show_window( self ): """ :return: """ self .deiconify() def on_exit( self ): """ :return: """ self .withdraw() |
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
2018-12-24 Adaptive Placeholders