Python图形编程探索系列-07-程序登录界面设计
设计任务
初步设计程序登录界面,详细分析设计步骤。
程序详细分析
基本框架设计
```
import tkinter as tk
import tkinter.messagebox
root = tk.Tk() # 创建应用程序窗口
root.title("用户登录界面设计")
root.geometry("230x100")
# --------功能块代码开始-------
--------功能块代码结束------
root.mainloop()
<h2 style="color:cyan;">设计标签用于提示用户</h2>
labelName = tk.Label(root, text='用户姓名:', justify=tk.RIGHT, width=80)
labelPwd = tk.Label(root, text='用户密码:', justify=tk.RIGHT, width=80)
<h2 style="color:cyan;">设计输入框</h2>
entryName = tk.Entry(root, width=80, textvariable=varName)
entryPwd = tk.Entry(root, show='*', width=80, textvariable=varPwd)
<h2 style="color:cyan;">设计按钮</h2>
buttonOk = tk.Button(root, text='登录', relief=tk.RAISED, command=login)
buttonCancel = tk.Button(root, text='重置', relief=tk.RAISED, command=cancel)
buttonquit = tk.Button(root, text='退出', relief=tk.RAISED, command=_quit)
<h2 style="color:cyan;">设计功能函数</h2>
**关联变量**
varName = tk.StringVar()
varName.set('')
varPwd = tk.StringVar()
varPwd.set('')
**登录按钮处理函数**
def login():
# 获取用户名和密码
name = entryName.get()
pwd = entryPwd.get()
if name == 'admin' and pwd == '123456':
tk.messagebox.showinfo(title='Python tkinter', message='OK')
else:
tk.messagebox.showerror('Python tkinter', message='Error')
**重新输入按钮处理函数**
def cancel():
# 清空用户输入的用户名和密码
varName.set('')
varPwd.set('')
**退出按钮处理函数**
def _quit():
root.quit()
root.destroy()
<h2 style="color:cyan;">各个组件排兵布阵</h2>
labelName.place(x=10, y=5, width=80, height=20)
labelPwd.place(x=10, y=30, width=80, height=20)
entryName.place(x=100, y=5, width=80, height=20)
entryPwd.place(x=100, y=30, width=80, height=20)
buttonOk.place(x=30, y=70, width=50, height=20)
buttonCancel.place(x=90, y=70, width=50, height=20)
buttonquit.place(x=150, y=70, width=50, height=20)
<h1 style="background:cyan;">完整程序组装</h1>
import tkinter as tk
import tkinter.messagebox
root = tk.Tk() # 创建应用程序窗口
root.title("用户登录界面设计")
root.geometry("230x100")
--------功能块代码开始-------
功能函数设计
varName = tk.StringVar()
varName.set('')
varPwd = tk.StringVar()
varPwd.set('')
def login():
# 获取用户名和密码
name = entryName.get()
pwd = entryPwd.get()
if name == 'admin' and pwd == '123456':
tk.messagebox.showinfo(title='Python tkinter', message='OK')
else:
tk.messagebox.showerror('Python tkinter', message='Error')
def cancel():
# 清空用户输入的用户名和密码
varName.set('')
varPwd.set('')
def _quit():
root.quit()
root.destroy()
主窗口中的各个组件设计
labelName = tk.Label(root, text='用户姓名:', justify=tk.RIGHT, width=80)
labelPwd = tk.Label(root, text='用户密码:', justify=tk.RIGHT, width=80)
entryName = tk.Entry(root, width=80, textvariable=varName)
entryPwd = tk.Entry(root, show='*', width=80, textvariable=varPwd)
buttonOk = tk.Button(root, text='登录', relief=tk.RAISED, command=login)
buttonCancel = tk.Button(root, text='重置', relief=tk.RAISED, command=cancel)
buttonquit = tk.Button(root, text='退出', relief=tk.RAISED, command=_quit)
主窗口中各个组件的排放位置 = 排兵布阵
labelName.place(x=10, y=5, width=80, height=20)
labelPwd.place(x=10, y=30, width=80, height=20)
entryName.place(x=100, y=5, width=80, height=20)
entryPwd.place(x=100, y=30, width=80, height=20)
buttonOk.place(x=30, y=70, width=50, height=20)
buttonCancel.place(x=90, y=70, width=50, height=20)
buttonquit.place(x=150, y=70, width=50, height=20)
--------功能块代码结束------
root.mainloop() # 窗口运行循环
<h1 style="background:cyan;">最终效果</h1>



Python图形编程探索系列-07-程序登录界面设计的更多相关文章
- Python图形编程探索系列-05-用控制变量构建对话程序
跳转到自己的博客 控制变量 变量 符号 意义 默认值 1 var = tk.BooleanVar() 布尔型 0 2 var = tk.StringVar() 字符串控制变量 空字符串 3 var = ...
- Python图形编程探索系列-09-tkinter与matplotlib结合案例
案例1 案例来自于:https://bbs.csdn.net/topics/390326088 代码示例: import matplotlib matplotlib.use('TkAgg') from ...
- Python图形编程探索系列-08-再次认识标签
标签的各种属性 代码展示: import tkinter as tk root = tk.Tk() root.geometry = '500x300' label1 = tk.Label(root, ...
- Python图形编程探索系列-06-按钮批量生产函数
设计任务 初步设计一个批量生产按钮的函数,根据需要的按钮数量,自动生成多少按钮. 函数设计 import tkinter as tk # 导入tkinter库 root = tk.Tk() # 建立程 ...
- Python图形编程探索系列-04-网上图片与标签组件的结合
跳转到自己的博客 任务设定 任务:从网上找到一张图片,然后将其显示在标签上? 网上图片网站:http://pic.58pic.com/58pic/17/56/38/52w58PICtER_1024.j ...
- Python图形编程探索系列-03-标签组件(Label)
跳转到自己的博客 tkinter.Label介绍 什么是标签? 通俗的将就相当于word的功能,能够进行显示不可修改的文字.图片或者图文混排. 直观体会一下 图1 背景图构成:内容区(黑色),填充区( ...
- Python图形编程探索系列-02-框架设计
跳转到我的博客 设计任务 在主窗口root中放置三个容器用于容纳组件,容器采用框架设计. 代码初步设计 import tkinter as tk root = tk.Tk() root.geometr ...
- Python图形编程探索系列-01-初级任务
设计任务 设计一个主窗口,在其中添加三个标签和三个按钮,当点击按钮时,对标签的内容和色彩进行修改. 代码初步设计 import tkinter as tk root = tk.Tk() def f1( ...
- Python Socket 编程——聊天室示例程序
上一篇 我们学习了简单的 Python TCP Socket 编程,通过分别写服务端和客户端的代码了解基本的 Python Socket 编程模型.本文再通过一个例子来加强一下对 Socket 编程的 ...
随机推荐
- python之random模块分析(一)
random是python产生伪随机数的模块,随机种子默认为系统时钟.下面分析模块中的方法: 1.random.randint(start,stop): 这是一个产生整数随机数的函数,参数start代 ...
- Project Euler Problem9
Special Pythagorean triplet Problem 9 A Pythagorean triplet is a set of three natural numbers, a b ...
- 读SRE Google运维解密有感(四)-聊聊问题排查
前言 这是读“SRE Google运维解密”有感第四篇,之前的文章可访问www.addops.cn来查看.今天我们来聊聊“问题排查”这个话题,本人到目前为止还在参与一线运维的工作,遇到过很多“稀奇古怪 ...
- c++ 引用方式传递数组
值传递 (pass by value),指针传递(pass by pointer),当发生函数调用时,需要给形参分配存储单元.当传递是对象时,要调用拷贝构造函数.而且指针最后析构时,要处理内存释放问题 ...
- zabbix3.0.4导入中文模板后乱码问题处理
通过yum安装方式部署了zabbix3.0.4监控服务器,配置过程中发现当导入的模板中有中文时,图中的中文会变成方块 如下图所示: 这个问题是由于zabbix的web端没有中文字库,我们最需要把中文字 ...
- robotium之webview元素处理
今天写robotium脚本发现,用uiautomatorviewer定位百度贴吧的登录框是无法定位的,如图: 明显无法定位用户名.密码输入框,无法定位元素那就无法对控件无法操作 如何定位webview ...
- Hive官方使用手册——新Hive CLI(Beeline CLI)
Hive官方使用手册——新Hive CLI(Beeline CLI) https://blog.csdn.net/maizi1045/article/details/79481686
- Android动画分类
动画分类 View动画(补间动画).帧动画.属性动画 View动画(补间动画)包括:平移.旋转.缩放.透明度,View动画是一种渐近式动画 帧动画:图片切换动画 属性动画:通过动态改变对象的属性达到动 ...
- react之异步请求数据,render先行渲染报错,未拿到数据
import React from 'react' import {connect} from 'react-redux' import { Redirect} from 'react-router- ...
- plsql developer连接Oracle报错ORA-12154: TNS:could not resolve the connect identifier specified
今日更改Oracle网络配置文件后使用plsql developer 尝试连接到Oracle出现报错 ORA-12154: TNS:could not resolve the connect iden ...