Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >python thinker增删改查 脚本

python thinker增删改查 脚本

作者头像
用户5760343
发布于 2022-05-13 09:16:26
发布于 2022-05-13 09:16:26
67100
代码可运行
举报
文章被收录于专栏:sktjsktj
运行总次数:0
代码可运行
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
"""
 Implement a GUI for viewing and updating class instances stored in a shelve;
 the shelve lives on the machine this script runs on, as 1 or more local files;
 """
from tkinter import *
 from tkinter.messagebox import showerror
 import shelve
 shelvename = 'class-shelve'
 fieldnames = ('name', 'age', 'job', 'pay')
class Person:
 def init(self, name, age, pay=0, job=None):
 self.name = name
 self.age  = age
 self.pay  = pay
 self.job  = job
 def lastName(self):
 return self.name.split()[-1]
 def giveRaise(self, percent):
 self.pay *= (1.0 + percent)
def makeWidgets():
 global entries
 window = Tk()
 window.title('People Shelve')
 form = Frame(window)
 form.pack()
 entries = {}
 for (ix, label) in enumerate(('key',) + fieldnames):
 lab = Label(form, text=label)
 ent = Entry(form)
 lab.grid(row=ix, column=0)
 ent.grid(row=ix, column=1)
 entries[label] = ent
 Button(window, text="Fetch",  command=fetchRecord).pack(side=LEFT)
 Button(window, text="Update", command=updateRecord).pack(side=LEFT)
 Button(window, text="Quit",   command=window.quit).pack(side=RIGHT)
 return window
def fetchRecord():
 key = entries['key'].get()
 try:
 record = db[key]                      # fetch by key, show in GUI
 except:
 showerror(title='Error', message='No such key!')
 else:
 for field in fieldnames:
 entries[field].delete(0, END)
 entries[field].insert(0, repr(getattr(record, field)))
def updateRecord():
 key = entries['key'].get()
 if key in db:
 record = db[key]                      # update existing record
 else:
 record = Person(name='?', age='?')    # eval: strings must be quoted
 for field in fieldnames:
 setattr(record, field, eval(entries[field].get()))
 db[key] = record
db = shelve.open(shelvename)
 window = makeWidgets()
 window.mainloop()
 db.close() # back here after quit or window close
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-05-13,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
CodeBuddy实现图片水印添加工具
如今,电商平台竞争激烈,辛苦拍摄的商品图极易被同行盗用。使用在线水印工具上传图片时,存在数据泄露风险,且第三方服务器存储的图片也可能被不法分子获取,导致商品图被盗用,辛苦打造的商品形象和销量被他人不劳而获。
Undoom
2025/05/24
1030
CodeBuddy实现图片水印添加工具
如今,电商平台竞争激烈,辛苦拍摄的商品图极易被同行盗用。使用在线水印工具上传图片时,存在数据泄露风险,且第三方服务器存储的图片也可能被不法分子获取,导致商品图被盗用,辛苦打造的商品形象和销量被他人不劳而获。
Undoom
2025/05/26
820
CodeBuddy实现图片水印添加工具
python编程preview
1、G.next() 2、pickle 用法 3、shelve 4、继承类的初始化写法:Obj.init 5 thinker from tkinter import * Label(text='Spam').pack() mainloop() 6、thinker button from tkinter import * from tkinter.messagebox import showinfo def reply(): showinfo(title='p
用户5760343
2022/05/13
4190
python编程preview
python tkinter(2)
1、设置label的字体、颜色、背景色、宽、高 from tkinter import * root = Tk() labelfont = ('times', 20, 'bold') # family, size, style widget = Label(root, text='Hello config world') widget.config(bg='black', fg='yellow') # yellow text on black label widget.config(font=labelfont) # use a larger font widget.config(height=3, width=20) # initial size: lines,chars widget.pack(expand=YES, fill=BOTH) root.mainloop() 2、bd设置边框、relief=设置边框类型,cursor鼠标
用户5760343
2022/05/13
8720
python tkinter(2)
python tkinter grid 网格
from tkinter import * colors = ['red', 'green', 'orange', 'white', 'yellow', 'blue']
用户5760343
2022/05/13
5340
​Python | GUI编程之tkinter (一)
本文内容为使用Python3的tkinter模块,开发GUI。在阅读本文前,请确保你已经或可能满足以下条件:
LogicPanda
2019/07/30
6.3K0
python tictactoe游戏
import random, sys, time from tkinter import * from tkinter.messagebox import showinfo, askyesno from guimaker import GuiMakerWindowMenu
用户5760343
2022/05/13
1.6K0
python tictactoe游戏
教你用Python写界面
作为Pyhon开发者,你迟早都会碰到图形用户界面(GUI)应用开发任务,这时候我们就需要一些界面库来帮助我们快速搭建界面,python的界面库很多,我认识的并不多,这里只列出几种我认识的
py3study
2020/01/07
4.7K0
教你用Python写界面
python 动态GUI表单生成器 脚本***
""" ################################################################## a reusable form class, used by getfilegui (and others) ################################################################## """
用户5760343
2022/05/13
6870
python 动态GUI表单生成器 脚本***
python guimixin 消息调用 工具dialog封装
""" ############################################################################### a "mixin" class for other frames: common methods for canned dialogs, spawning programs, simple text viewers, etc; this class must be mixed with a Frame (or a subclass derived from Frame) for its quit method ############################################################################### """
用户5760343
2022/05/13
3230
python调用chatgpt接口代码有界面,多次优化 chatGPT生成的
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # @时间: 2023/3/9 15:17 # @文件: chat_gpt_ui.py import tkinter from tkinter import simpledialog import tkinter as tk from tkinter import messagebox import openai import json class ChatGPTUI: def __init
纯情
2023/04/26
4230
python pyview幻灯片展示
""" ###################################################################### SlideShow: a simple photo image slideshow in Python/tkinter; the base feature set coded here can be extended in subclasses; ###################################################################### """
用户5760343
2022/05/13
1.9K0
python pyview幻灯片展示
python3+opencv+tkint
其中所使用到的训练参数数据下载地址:https://github.com/opencv/opencv/tree/master/data/haarcascades
py3study
2020/01/17
6670
Python初学——窗口视窗Tkinter
此篇文章是跟着沫凡小哥的视频学习的,附上学习网址:https://morvanzhou.github.io/tutorials/python-basic/ 什么是 tkinter 窗口 1.1 什么是
闪电gogogo
2018/01/08
6.7K0
Python初学——窗口视窗Tkinter
python tkinter输入表单
""" use StringVar variables lay out by columns: this might not align horizontally everywhere (see entry2) """
用户5760343
2022/05/13
1.2K0
python开发的简单窗口界面的倒计时界面
下面的代码通过Tkinter制作windows窗口界面,然后时间了一个简单的倒计时功能,代码可以直接运行
代码伴一生
2021/11/03
9550
基于tkinter的GUI编程
tkinter:tkinter是绑定了Python的TKGUI工具集,就是Python包装的Tcl代码,通过内嵌在Python解释器内部的Tcl 解释器实现的,它是Python标准库的一部分,所以使用它进行GUI编程不需要另外安装第三方库的。
py3study
2020/01/16
5.8K0
基于tkinter的GUI编程
python textEditor 自制编辑器
""" ############################################################################### An extended Frame that makes window menus and toolbars automatically. Use GuiMakerFrameMenu for embedded components (makes frame-based menus). Use GuiMakerWindowMenu for top-level windows (makes Tk8.0 window menus). See the self-test code (and PyEdit) for an example layout tree format. ############################################################################### """
用户5760343
2022/05/13
1.3K0
python textEditor 自制编辑器
python tkinter
1、 from tkinter import Label widget=Label(None,text='Hello Gui') widget.pack() widget.mainloop() 2| expand fill:组件随窗口调整大小 from tkinter import * widget=Label(None,text='Hello Gui') widget.pack(expand=YES,fill=BOTH) widget.mainloop()
用户5760343
2022/05/13
1.4K0
python tkinter
python tkinter(3) menu 例子
2、optionmenu from tkinter import * root = Tk()
用户5760343
2022/05/13
7290
python tkinter(3) menu 例子
相关推荐
CodeBuddy实现图片水印添加工具
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验