前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >python编程preview

python编程preview

作者头像
用户5760343
发布于 2022-05-13 09:19:48
发布于 2022-05-13 09:19:48
41900
代码可运行
举报
文章被收录于专栏:sktjsktj
运行总次数:0
代码可运行

1、G.next()

2、pickle 用法

3、shelve

4、继承类的初始化写法:Obj.init

5 thinker

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 from tkinter import *
 Label(text='Spam').pack()
 mainloop()
 6、thinker button
 from tkinter import *
 from tkinter.messagebox import showinfo
def reply():
 showinfo(title='popup', message='Button pressed!')
window = Tk()
 button = Button(window, text='press', command=reply)
 button.pack()
 window.mainloop()
 7、thinker Tk()/showinfo()/Entry()/Label()/Button()
 from tkinter import *
 from tkinter.messagebox import showinfo
def reply(name):
 showinfo(title='Reply', message='Hello %s!' % name)
top = Tk()
 top.title('Echo')

top.iconbitmap('py-blue-trans-out.ico')

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Label(top, text="Enter your name:").pack(side=TOP)
 ent = Entry(top)
 ent.pack(side=TOP)
 btn = Button(top, text="Submit", command=(lambda: reply(ent.get())))
 btn.pack(side=LEFT)
top.mainloop()
 8、cgi::::::
 """
 Implement a web-based interface for viewing and updating class instances
 stored in a shelve; the shelve lives on server (same machine if localhost)
 """
import cgi, shelve, sys, os                   # cgi.test() dumps inputs
 shelvename = 'class-shelve'                   # shelve files are in cwd
 fieldnames = ('name', 'age', 'job', 'pay')
form = cgi.FieldStorage()                     # parse form data
 print('Content-type: text/html')              # hdr, blank line is in replyhtml
 sys.path.insert(0, os.getcwd())               # so this and pickler find person

main html template

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
replyhtml = """
 <html>
 <title>People Input Form</title>
 <body>
 <form method=POST action="peoplecgi.py">
 <table>
 <tr><th>key<td><input type=text name=key value="%(key)s">
 
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制

 </table>
 <p>
 <input type=submit value="Fetch",  name=action>
 <input type=submit value="Update", name=action>
 </form>
 </body></html>
 """

insert html for data rows at

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
rowhtml  = '<tr><th>%s<td><input type=text name=%s value="%%(%s)s">\n'
 rowshtml = ''
 for fieldname in fieldnames:
 rowshtml += (rowhtml % ((fieldname,) * 3))
 replyhtml = replyhtml.replace('
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
', rowshtml)
def htmlize(adict):
 new = adict.copy()
 for field in fieldnames:                       # values may have &, >, etc.
 value = new[field]                         # display as code: quoted
 new[field] = cgi.escape(repr(value))       # html-escape special chars
 return new
def fetchRecord(db, form):
 try:
 key = form['key'].value
 record = db[key]
 fields = record.dict                   # use attribute dict
 fields['key'] = key                        # to fill reply string
 except:
 fields = dict.fromkeys(fieldnames, '?')
 fields['key'] = 'Missing or invalid key!'
 return fields
def updateRecord(db, form):
 if not 'key' in form:
 fields = dict.fromkeys(fieldnames, '?')
 fields['key'] = 'Missing key input!'
 else:
 key = form['key'].value
 if key in db:
 record = db[key]                       # update existing record
 else:
 from person import Person              # make/store new one for key
 record = Person(name='?', age='?')     # eval: strings must be quoted
 for field in fieldnames:
 setattr(record, field, eval(form[field].value))
 db[key] = record
 fields = record.dict
 fields['key'] = key
 return fields
db = shelve.open(shelvename)
 action = form['action'].value if 'action' in form else None
 if action == 'Fetch':
 fields = fetchRecord(db, form)
 elif action == 'Update':
 fields = updateRecord(db, form)
 else:
 fields = dict.fromkeys(fieldnames, '?')        # bad submit button value
 fields['key'] = 'Missing or invalid action!'
 db.close()
 print(replyhtml % htmlize(fields))                 # fill reply from dict
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-05-13,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
python thinker增删改查 脚本
""" 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 shelvenam
用户5760343
2022/05/13
6710
python 动态GUI表单生成器 脚本***
""" ################################################################## a reusable form class, used by getfilegui (and others) ################################################################## """
用户5760343
2022/05/13
6870
python 动态GUI表单生成器 脚本***
Python:GUI
# code: utf-8 # writer: Geovin Du 涂聚 文 import os; import sys; from tkinter import *; #GUI 自带的 另有:wxPython,PyQt5,PythonCard,Dabo等 from tkinter.messagebox import showinfo; def reply(name): showinfo(title='GUI测试', message='你好! %s!' % name); # 应用
py3study
2020/01/15
9680
python tkinter输入表单
""" use StringVar variables lay out by columns: this might not align horizontally everywhere (see entry2) """
用户5760343
2022/05/13
1.2K0
python ftp下载文件 脚本
------------------------------------------getfile.py
用户5760343
2022/05/13
1.2K0
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 弹出框 压缩文件 解压文件
from tkinter import * # widgets and presets from tkinter.filedialog import askopenfilename # file selector dialog
用户5760343
2022/05/13
9810
python 弹出框 压缩文件 解压文件
目录
Python有很多GUI框架,但是Tkinter是Python标准库中唯一内置的框架。
互联网金融打杂
2022/08/01
30.6K0
目录
Salesforce学习 Lwc(三)自定义开发时进行Validation验证
我们在使用 【lightning-record-edit-form】标签开发过程中,表单提交之后,画面输入的内容不符合要求时,error信息显示在项目上。
repick
2020/12/15
9250
Salesforce LWC学习(二十二) 简单知识总结篇二
https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.reactivity_fields
Zero-Zhang
2020/09/01
5650
Salesforce LWC学习(二十二) 简单知识总结篇二
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 tkinter grid 网格
from tkinter import * colors = ['red', 'green', 'orange', 'white', 'yellow', 'blue']
用户5760343
2022/05/13
5340
Tkinter 入门之旅
Tkinter 作为 Python 的标准库,是非常流行的 Python GUI 工具,同时也是非常容易学习的,今天我们就来开启 Tkinter 的入门之旅
周萝卜
2021/11/08
6.9K0
Salesforce学习 Lwc(九)【数据初期取得与更新】运用详解
开发自定义画面经常遇到的场景就是增删改查,关于数据更新用到的几个方法进行一下总结,常用到的有以下几种。
repick
2020/12/29
1.1K0
基于tkinter的GUI编程
tkinter:tkinter是绑定了Python的TKGUI工具集,就是Python包装的Tcl代码,通过内嵌在Python解释器内部的Tcl 解释器实现的,它是Python标准库的一部分,所以使用它进行GUI编程不需要另外安装第三方库的。
py3study
2020/01/16
5.8K0
基于tkinter的GUI编程
python 文件下载服务器 脚本
import sys, os, time, _thread as thread from socket import *
用户5760343
2022/05/13
2.4K0
Python|GUI编程中Entry部件详解
Entry小部件是Tkinter的基本小部件,用于从应用程序的用户获取输入,即文本字符串。这个小部件允许用户输入一行文本。如果用户输入的字符串比小部件的可用显示空间长,则将滚动内容。这意味着不能看到字符串的整体。箭头键可用于移动到字符串的不可见部分。如果要输入多行文本,则必须使用文本小部件。
算法与编程之美
2020/04/26
2K0
Salesforce LWC学习(二十一) Error浅谈
本篇参考:https://developer.salesforce.com/docs/component-library/documentation/en/lwc/data_error
Zero-Zhang
2020/08/25
1.2K0
Salesforce LWC学习(二十一) Error浅谈
源创库 | Python GUI初步认识与C/S端发展之我见
今天翻了翻《Python编程(第四版)》,这本书其实买来还是有点久的,毕竟现在Python 3.9都出来了,这书是Python 3.1/3.2 Beta的示例。当然也暴露了我这书买来没怎么翻过的事实
ZNing
2021/09/24
7450
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 thinker增删改查 脚本
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验