数据库监测工具2.0
本帖最后由 phantomxjc 于 2024-5-16 11:19 编辑只写语句,不打包需要的自己改哦```
#数据库监控工具2.0
import tkinter as tk
from tkinter import ttk, messagebox, simpledialog
import os
import cx_Oracle
import time
import threading
from tkinter.ttk import Treeview
class demo(tk.Tk):
def __init__(self):
super().__init__()
self.title("数据库监控工具")
self.geometry("1200x400")
self.resizable(True, True)
#self.attributes("-alpha", 0.7)
# 创建笔记本卡片
self.notebook = ttk.Notebook(self)
self.notebook.pack(expand=True, fill="both")
# 创建查询卡片
self.sttscx = tk.Frame(self.notebook)
self.notebook.add(self.sttscx, text="监控事项")
self.sttscx_list = Treeview(self.sttscx,columns=('c1', 'c2', 'c3',
'c4', 'c5', 'c6','c7'),
show="headings")
self.sttscx_list.pack(expand=True, fill="both")
# 设置每列宽度和对齐方式
self.sttscx_list.column('c1', width=100, anchor='center')
self.sttscx_list.column('c2', width=300, anchor='center')
self.sttscx_list.column('c3', width=200, anchor='center')
self.sttscx_list.column('c4', width=300, anchor='center')
self.sttscx_list.column('c5', width=100, anchor='center')
self.sttscx_list.column('c6', width=100, anchor='center')
self.sttscx_list.column('c7', width=100, anchor='center')
# 设置每列表头标题文本
self.sttscx_list.heading('c1', text='事项')
self.sttscx_list.heading('c2', text='事项')
self.sttscx_list.heading('c3', text='事项')
self.sttscx_list.heading('c4', text='事项')
self.sttscx_list.heading('c5', text='事项')
self.sttscx_list.heading('c6', text='事项')
self.sttscx_list.heading('c7', text='事项')
self.sttscx_list.pack(side=tk.LEFT, fill=tk.Y)
# 创建事项查询卡片
self.qrnrksxcx = tk.Frame(self.notebook)
self.notebook.add(self.qrnrksxcx, text="监控事项")
self.qrnrksxcx_list = Treeview(self.qrnrksxcx, columns=('c1', 'c2', 'c3',
'c4', 'c5', 'c6', 'c7'),
show="headings")
self.qrnrksxcx_list.pack(expand=True, fill="both")
# 设置每列宽度和对齐方式
self.qrnrksxcx_list.column('c1', width=100, anchor='center')
self.qrnrksxcx_list.column('c2', width=300, anchor='center')
self.qrnrksxcx_list.column('c3', width=150, anchor='center')
self.qrnrksxcx_list.column('c4', width=300, anchor='center')
self.qrnrksxcx_list.column('c5', width=100, anchor='center')
self.qrnrksxcx_list.column('c6', width=100, anchor='center')
self.qrnrksxcx_list.column('c7', width=150, anchor='center')
# 设置每列表头标题文本
self.qrnrksxcx_list.heading('c1', text='事项')
self.qrnrksxcx_list.heading('c2', text='事项')
self.qrnrksxcx_list.heading('c3', text='事项')
self.qrnrksxcx_list.heading('c4', text='事项')
self.qrnrksxcx_list.heading('c5', text='事项')
self.qrnrksxcx_list.heading('c6', text='事项')
self.qrnrksxcx_list.heading('c7', text='事项')
self.qrnrksxcx_list.pack(side=tk.LEFT, fill=tk.Y)
# 创建查询卡片
self.jsydtj = tk.Frame(self.notebook)
self.notebook.add(self.jsydtj, text="事项")
self.jsydtj_list = Treeview(self.jsydtj, columns=('c1', 'c2', 'c3',
'c4', 'c5'),
show="headings")
self.jsydtj_list.pack(expand=True, fill="both")
# 设置每列宽度和对齐方式
self.jsydtj_list.column('c1', width=200, anchor='center')
self.jsydtj_list.column('c2', width=400, anchor='center')
self.jsydtj_list.column('c3', width=200, anchor='center')
self.jsydtj_list.column('c4', width=200, anchor='center')
self.jsydtj_list.column('c5', width=200, anchor='center')
# 设置每列表头标题文本
self.jsydtj_list.heading('c1', text='事项')
self.jsydtj_list.heading('c2', text='事项')
self.jsydtj_list.heading('c3', text='事项')
self.jsydtj_list.heading('c4', text='事项')
self.jsydtj_list.heading('c5', text='事项')
self.jsydtj_list.pack(side=tk.LEFT, fill=tk.Y)
#事项
self.wrksx = tk.Frame(self.notebook)
self.notebook.add(self.wrksx, text="监控事项")
self.wrksx_list = Treeview(self.wrksx, columns=('c1', 'c2', 'c3',
'c4', 'c5', 'c6', 'c7'),
show="headings")
self.wrksx_list.pack(expand=True, fill="both")
# 设置每列宽度和对齐方式
self.wrksx_list.column('c1', width=100, anchor='center')
self.wrksx_list.column('c2', width=300, anchor='center')
self.wrksx_list.column('c3', width=200, anchor='center')
self.wrksx_list.column('c4', width=300, anchor='center')
self.wrksx_list.column('c5', width=100, anchor='center')
self.wrksx_list.column('c6', width=100, anchor='center')
self.wrksx_list.column('c7', width=100, anchor='center')
# 设置每列表头标题文本
self.wrksx_list.heading('c1', text='事项')
self.wrksx_list.heading('c2', text='事项')
self.wrksx_list.heading('c3', text='事项')
self.wrksx_list.heading('c4', text='事项')
self.wrksx_list.heading('c5', text='事项')
self.wrksx_list.heading('c6', text='事项')
self.wrksx_list.heading('c7', text='事项')
self.wrksx_list.pack(side=tk.LEFT, fill=tk.Y)
self.fetch_data_and_update_tree()
self.refresh_tree()
def connect_to_oracle(self):
# 这里填写你的数据库连接信息
conn = cx_Oracle.connect()
return conn
# 执行查询并更新Treeview的函数
def fetch_data_and_update_tree(self):
conn = self.connect_to_oracle()
cursor = conn.cursor()
sql1 = ""
sql2 = ""
sql3 = ""
sql4 = ""
cursor.execute(sql1)# 替换为你的表名和列名
rows = cursor.fetchall()
cursor.execute(sql2)
rows2 = cursor.fetchall()
cursor.execute(sql3)
rows3 = cursor.fetchall()
cursor.execute(sql4)
rows4 = cursor.fetchall()
# 清空Treeview中的现有项
for item in self.sttscx_list.get_children():
self.sttscx_list.delete(item)
# 插入新数据到Treeview
for row in rows:
self.sttscx_list.insert("", "end", values=(row, row, row,row,row, row, row))
for item in self.qrnrksxcx_list.get_children():
self.qrnrksxcx_list.delete(item)
# 插入新数据到Treeview
for row in rows2:
self.qrnrksxcx_list.insert("", "end", values=(row, row, row,row,row, row, row))
for item in self.jsydtj_list.get_children():
self.jsydtj_list.delete(item)
# 插入新数据到Treeview
for row in rows3:
self.jsydtj_list.insert("", "end", values=(row, row, row,row,row))
for item in self.wrksx_list.get_children():
self.wrksx_list.delete(item)
# 插入新数据到Treeview
for row in rows4:
self.wrksx_list.insert("", "end", values=(row, row, row,row,row, row, row))
cursor.close()
conn.close()
# 刷新Treeview的函数(递归调用以定期更新)
def refresh_tree(self):
self.fetch_data_and_update_tree()
# 5000毫秒后再次调用refresh_tree
self.after(5000, lambda: self.refresh_tree())
if __name__ == "__main__":
app = demo()
app.mainloop()
```
效果图如下:
jun269 发表于 2024-5-16 11:57
楼主,这玩意不是每个人都能有能力修改的,也不是每个人都能有能力打包的。
确实如此,我是因为自己的工作而做的,但是要改一个普适版本出来还要不少工作,所以没搞普适版本
,希望有能力的友友自己改一改哦,我这个也挺简单的,懂基本的python语法就能改动了
Seay那个MySQL的插件也不错 多谢分享代码,下载学习下 ceciliaaii 发表于 2024-5-16 11:26
Seay那个MySQL的插件也不错
我不懂mysql,只会用oracle
lzf880 发表于 2024-5-16 11:27
多谢分享代码,下载学习下
哈哈
可以的一起加油
楼主,这玩意不是每个人都能有能力修改的,也不是每个人都能有能力打包的。 楼主真厉害! 向你学习! 麻烦多说几句使用场景,解决哪些痛点
页:
[1]
2