tkinter 连接数据库的可视化界面---二

直接代码

# -*- coding: utf-8 -*-
"""
Created on Wed Nov  6 08:56:57 2019

@author: 01
"""

# -*- coding:utf-8 -*-

import MySQLdb
from hashlib import sha1
import tkinter
import tkinter.filedialog
import os
from PIL import ImageGrab
from time import sleep
from tkinter import *
import cv2
from PIL import Image,ImageTk
from tkinter.filedialog import askopenfilename
import json
import codecs
from tkinter.filedialog import askdirectory
import tkinter.messagebox
import sys,time

root1 = tkinter.Tk()
root1.title('登录')
root1.geometry('400x400+100+50')
      #name = input("请输入用户名:")
      # pwd = input("请输入密码:")
aa = StringVar()
aa.set('用户名')
aaa = tkinter.Label(root1, textvariable=aa)
aaa.place(x=200, y=150)
      
      
name = tkinter.Entry(root1,width=12,name="ss")
name.place(x =100 , y=100,width = 250, height=40,anchor = NW)
      
       
bb = StringVar()
bb.set('登录密码')
bbb = tkinter.Label(root1, textvariable=bb)
bbb.place(x=200, y=250)  
      
     
pwd =tkinter.Entry(root1,width=12)
pwd.place(x =100 , y=200,width = 250, height=40,anchor = NW)
      

#登录界面===============================================
def jiunu():      
        global root1
        db = MySQLdb.connect(host='192.168.2.41',port=3306,user='root',passwd='newpassword',db='photo',charset='utf8')

# 使用cursor()方法获zhoua取操作游标 
        cursor = db.cursor()
            # 判断用户名是否存在
        sql = 'select user_password from user where user_name=%s'
            # params = [uname]
        cursor.execute(sql, (name.get(),))
        a=name.get()
        data = cursor.fetchone()
        db.close()

        words = pwd.get()
        print("a",words)
        root1.destroy()
        while(words!=data[0]): #如果密码正确,摧毁登陆界面
          return 0
        
        def cv_imread(filePath):  
            cv_img=cv2.imdecode(np.fromfile(filePath,dtype=np.uint8),-1)  
            ## imdecode读取的是rgb,如果后续需要opencv处理的话,需要转换成bgr,转换后图片颜色会变化    ##cv_img=cv2.cvtColor(cv_img,cv2.COLOR_RGB2BGR)   
            return cv_img
        # 创建tkinter主窗口
        root = tkinter.Tk()
        
        root.title('图片处理')
        
        # 指定主窗口位置与大小
        root.geometry('1300x800+100+50')   # width x height + widthoffset + heightoffset
        
        # 不允许改变窗口大小
        root.resizable(False, False)
        root.focusmodel()
        
        def buttonCaptureClick():   
            #xy_text.set(str(file_entry.get()))
            xy_text.set(str(file_entry.get()).split('/')[-1][0:-4])
            
        def checkid():   
            #xy_text.set(str(file_entry.get()))
            print("name.get()",a)
            xy_text1.set(str(a))
        
        #获取输入的标注内容
        def getstr():
            if input_valueText.get() != '':
                words = input_valueText.get()
                get_label["text"] = words
        
        def selectPath1():
             db = MySQLdb.connect(host='192.168.2.41',port=3306,user='root',passwd='newpassword',db='photo',charset='utf8')
             db.autocommit(True)
# 使用cursor()方法获zhoua取操作游标 
             cursor = db.cursor()       
             path_ = askdirectory()            
             #sql = 'select user_password from user where user_name=%s'       
             j=0                           
             for i in os.listdir(path_):
                 print("as",i)
                 create_time = time.strftime('%y%m%d%H%M%S',time.localtime())+str(j)
                 sql = "INSERT INTO photo(source, photo_id, save_path,upload_name) VALUES(%d,\'%s\',\'%s\',\'%s\')" %(1,create_time,i,a)
            # params = [uname]
                 j=j+1
                 cursor.execute(sql)
             db.close()
             result = tkinter.messagebox.askokcancel(title = '提示',message='数据全部导入数据库')
             print(result)
             
        def save_jsonfile():
            print("list_content",list_content)
        
        # 定义坐标显示位置
        xy_text = StringVar()
        xy_text1 = StringVar()
        
        #打开图片文件并显示
        def choosepic():
            path_ = askopenfilename()
            path.set(path_)
            img_open = Image.open(file_entry.get())
            img_open=img_open.resize((600, 650))
            img = ImageTk.PhotoImage(img_open)
            image_label.config(image=img)
            image_label.image = img  # keep a reference
        def database_choosepic():
            db = MySQLdb.connect(host='192.168.2.41',port=3306,user='root',passwd='newpassword',db='photo',charset='utf8')
            db.autocommit(True)
# 使用cursor()方法获zhoua取操作游标 
            cursor = db.cursor()
            sql = """select
 a.photo_id,
 a.save_path,
 b.label_id,
 b.label_name
from
 photo.photo a
cross join photo.label b
left join photo.photo_label c on
 a.photo_id = c.photo_id
 and b.label_id = c.label_id
where
 a.is_delete = 0
 and b.is_delete = 0
 and a.is_lock = 0
 and c.id is null
order by
 a.create_time asc,
 b.`order` asc
limit 25"""
            cursor.execute(sql)
            photo_nsddame=cursor.fetchall();
           # print("photo_ndsdame",photo_nsddame[1:5][1:5])
            #计算未打标签的个数。    
            name_labeal=[]
            shuzu=[]
            for i in photo_nsddame:
                name_labeal.append(i[3])
                #print(i[3])
                shuzu.append(i[0])
            user_dict = {}
            for user in shuzu:
                if user not in user_dict:
                   user_dict[user] = 1
                else:
                   user_dict[user] +=1
            id_name_a=shuzu[0]
            NO_label_number=user_dict[id_name_a]

            for i in range(NO_label_number):
              #print(i)
               
              label_name_1=name_labeal[i] 
              print("label_name_1",label_name_1)
              if (label_name_1=='头发遮眉毛'):               
                sd=tkinter.Checkbutton(root, text=label_name_1, command=click_1) 
                if (i<=5):
                    z=120+30*i
                    sd.place(x =720 , y=z)
                if (5<i<=11):
                    z=120+30*(i-6)
                    sd.place(x =840 , y=z)
                if (11<i<=17):
                    z=120+30*(i-12)
                    sd.place(x =960 , y=z)
                if (17<i<=24):
                    z=120+30*(i-18)
                    sd.place(x =1080 , y=z)
                if (24<i<=25):
                    z=120
                    sd.place(x =1200 , y=z)
              if (label_name_1=='头发遮耳朵'):               
                sd=tkinter.Checkbutton(root, text=label_name_1, command=click_2) 
                if (i<=5):
                    z=120+30*i
                    sd.place(x =720 , y=z)
                if (5<i<=11):
                    z=120+30*(i-6)
                    sd.place(x =840 , y=z)
                if (11<i<=17):
                    z=120+30*(i-12)
                    sd.place(x =960 , y=z)
                if (17<i<=24):
                    z=120+30*(i-18)
                    sd.place(x =1080 , y=z)
                if (24<i<=25):
                    z=120
                    sd.place(x =1200 , y=z)
            
              if (label_name_1=='头发遮肩膀'):               
                sd=tkinter.Checkbutton(root, text=label_name_1, command=click_3) 
                if (i<=5):
                    z=120+30*i
                    sd.place(x =720 , y=z)
                if (5<i<=11):
                    z=120+30*(i-6)
                    sd.place(x =840 , y=z)
                if (11<i<=17):
                    z=120+30*(i-12)
                    sd.place(x =960 , y=z)
                if (17<i<=24):
                    z=120+30*(i-18)
                    sd.place(x =1080 , y=z)
                if (24<i<=25):
                    z=120
                    sd.place(x =1200 , y=z)
              if (label_name_1=='头发蓬散'):               
                sd=tkint
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值