zoukankan      html  css  js  c++  java
  • 寒假大数据学习笔记八

      今天学习Tkinter,但一上来就碰到了一个坑:tkinter的PhotoImage不支持jpg格式的图片,似乎它只支持gif(放上去gif也是不能动的gif)。如果使用了jpg格式的图片就会出现如下截图:

       上网查询,网上的解决方案是使用Pillow的Image和ImageTk,截止到这一步还没有什么问题,Pillow库存在:

      但在使用模块时出问题了:系统只能找到Image库,却找不到ImageTk库!我尝试上网搜索答案,却没有找到,在尝试了从pycharm中查询、pip安装等方法无果后,我干脆直接删除了Pillow,重装了一次,然后就发现ImageTk库又有了。折腾了一个小时,才发现重装果然是最有效的方法。

      此外,我还练习了一下Python连接mysql数据库,比较简单,附上代码:

     1 import pymysql
     2 
     3 # 打开连接
     4 
     5 
     6 def open_conn(dbname):
     7     db = pymysql.connect(
     8         host="localhost",
     9         port=3306,
    10         user="root",
    11         passwd="123456",
    12         db=dbname,
    13         charset="utf8")
    14 
    15     return db
    16 
    17 # 遍历查询
    18 
    19 
    20 def query(db):
    21 
    22     cursor = db.cursor()
    23     sql = "select * from newdemo"
    24     cursor.execute(sql)
    25     for each in cursor.fetchall():
    26         print(each)
    27 
    28 # 增加数据
    29 
    30 
    31 def add(db):
    32 
    33     cursor = db.cursor()
    34     sql = "insert into newdemo(name,sex,hobby,address,PS) values('马冬梅','男','打篮球','中国','无')"
    35     cursor.execute(sql)
    36     db.commit()
    37     # 查看插入后的结果
    38     sql = "select * from newdemo where name ='马冬梅'"
    39     cursor.execute(sql)
    40     for each in cursor.fetchall():
    41         print(each)
    42 
    43 # 修改数据
    44 
    45 
    46 def update(db):
    47     cursor = db.cursor()
    48     sql = " update newdemo set sex='女' where name='马冬梅'"
    49     cursor.execute(sql)
    50     db.commit()
    51     # 查看更新后的结果
    52     sql = "select * from newdemo where name='马冬梅'"
    53     cursor.execute(sql)
    54     for each in cursor.fetchall():
    55         print(each)
    56 
    57 
    58 # 删除数据
    59 
    60 def delete(db):
    61     cursor = db.cursor()
    62     sql = " delete from newdemo where name='马冬梅'"
    63     cursor.execute(sql)
    64     db.commit()
    65     # 查看更新后的结果
    66     sql = "select * from newdemo where name='马冬梅'"
    67     cursor.execute(sql)
    68     for each in cursor.fetchall():
    69         print(each)
    70 
    71 
    72 if __name__ == '__main__':
    73     # query(open_conn("demo"))
    74     # add(open_conn("demo"))
    75     # update(open_conn("demo"))
    76     # delete(open_conn("demo"))
    77     pass
  • 相关阅读:
    132123
    (一)robotframework自动化环境搭建
    python读取xlsx、csv、txt、html文件
    (二)robotframework自动化中遇到的错误及解决思路
    python使用小技巧
    三生零基础大白菜自动重装系统教程
    安装JDK和配置环境变量
    webpack 一套工程代码 管理多个相似项目
    box2dWeb 学习笔记
    简单计时器
  • 原文地址:https://www.cnblogs.com/YXSZ/p/12268363.html
Copyright © 2011-2022 走看看