首页 > 编程语言 >用python的tk写一个界面

用python的tk写一个界面

时间:2023-09-17 17:37:56浏览次数:37  
标签:10 界面 python text tk row root pg

记录一下,tk写界面的方法。

用python的tk写一个界面_python

import tkinter as tk
import pyautogui as pg
import time
import pyperclip  #剪切板调用

#主体窗口设置#
root = tk.Tk()
root.title("护理记录")
root.geometry('550x550+0+0')
root.attributes("-topmost",1)
font=('宋体',14)
#窗口大小固定
root.resizable(0,0)

#pyautogui每一步之间延迟时间 保护措施
#pg.PAUSE = 0.3
#pg.FAILSAFE = True #故障保护功能
#secs_between_keys = 0.5 #输入时间间隔
#num_seconds = 0.5 #鼠标移动速度

#数值定义
    #鼠标位置定义
testX = tk.StringVar()
testY = tk.StringVar()
    #年月日定义  时间
text_nyr = tk.StringVar()
text_nyr.set('2022:12:30')
text_nyr_x = tk.StringVar()
text_nyr_y = tk.StringVar()
text_xs_x = tk.StringVar()
text_xs_y = tk.StringVar()
text_nyr_x.set('926')
text_nyr_y.set('120')
text_xs_x.set('930')
text_xs_y.set('148')


##填写部分组件定义
    #意识
text_ys_x = tk.StringVar()
text_ys_y = tk.StringVar()
text_ys = tk.StringVar()
text_ys.set("清楚")
text_ys_x.set('933')
text_ys_y.set('167')
    #体温
text_tw = tk.StringVar()
text_tw.set("36.5")
text_tw_x = tk.StringVar()
text_tw_y = tk.StringVar()
text_tw_x.set('934')
text_tw_y.set('193')
    #脉搏
text_mb = tk.StringVar()
text_mb.set("80")
text_mb_x = tk.StringVar()
text_mb_y = tk.StringVar()
text_mb_x.set('914')
text_mb_y.set('210')
#呼吸
text_hx = tk.StringVar()
text_hx.set("20")
text_hx_x = tk.StringVar()
text_hx_y = tk.StringVar()
text_hx_x.set('929')
text_hx_y.set('237')
#收缩压
text_ssy = tk.StringVar()
text_ssy.set("118")
text_ssy_x = tk.StringVar()
text_ssy_y = tk.StringVar()
text_ssy_x.set('929')
text_ssy_y.set('260')
#舒张压
text_szy = tk.StringVar()
text_szy.set("76")
text_szy_x = tk.StringVar()
text_szy_y = tk.StringVar()
text_szy_x.set('938')
text_szy_y.set('283')
#遵遗嘱治疗
text_zyz = tk.StringVar()
text_zyz.set("今日遵医嘱继续治疗。")
text_zyz_x = tk.StringVar()
text_zyz_y = tk.StringVar()
text_zyz_x.set('963')
text_zyz_y.set('416')
#三个斜杠坐标
text_xg1_x = tk.StringVar()
text_xg1_y = tk.StringVar()
text_xg1_x.set('924')
text_xg1_y.set('353')

text_xg2_x = tk.StringVar()
text_xg2_y = tk.StringVar()
text_xg2_x.set('924')
text_xg2_y.set('374')

text_xg3_x = tk.StringVar()
text_xg3_y = tk.StringVar()
text_xg3_x.set('924')
text_xg3_y.set('398')
#血氧
text_xueyang_x = tk.StringVar()
text_xueyang_y = tk.StringVar()
text_xueyang_x.set('924')
text_xueyang_y.set('307')
#吸氧
text_xiyang_x = tk.StringVar()
text_xiyang_y = tk.StringVar()
text_xiyang_x.set('924')
text_xiyang_y.set('330')

#鼠标位置方法
def test_shubiao():
    opt1 = testX.get()
    result = eval(opt1)
    opt2 = testY.get()
    result2 = eval(opt2)
    x, y = result, result2
    pg.moveTo(x, y,duration = 0.3)

def sevenfun():
    pg.moveTo(62, 138)
    pg.click()
    tmpx = text_nyr_x.get()
    tmpy = text_nyr_y.get()
    xstmpx = text_xs_x.get()
    xstmpy = text_xs_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.press("backspace",10,0.2)
    pg.click()
    pg.hotkey("ctrl", "v")
    pg.moveTo(eval(xstmpx), eval(xstmpy))
    pg.click()
    pg.press("backspace",5,0.2)
    pg.click()
    pg.write("07:00")
    pg.moveTo(180, 150)

def forutfun():
    pg.moveTo(62, 138)
    pg.click()
    tmpx = text_nyr_x.get()
    tmpy = text_nyr_y.get()
    xstmpx = text_xs_x.get()
    xstmpy = text_xs_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.press("backspace",10,0.2)
    pg.click()
    pg.hotkey("ctrl", "v")
    pg.moveTo(eval(xstmpx), eval(xstmpy))
    pg.click()
    pg.press("backspace",5,0.2)
    pg.click()
    pg.write("14:00")
    pg.moveTo(180, 150)

def eightfun():
    pg.moveTo(62, 138)
    pg.click()
    tmpx = text_nyr_x.get()
    tmpy = text_nyr_y.get()
    xstmpx = text_xs_x.get()
    xstmpy = text_xs_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.press("backspace",10,0.2)
    pg.click()
    pg.hotkey("ctrl", "v")
    pg.moveTo(eval(xstmpx), eval(xstmpy))
    pg.click()
    pg.press("backspace",5,0.2)
    pg.click()
    pg.write("18:00")
    pg.moveTo(180, 150)

def tweentyfun():
    pg.moveTo(62, 138)
    pg.click()
    tmpx = text_nyr_x.get()
    tmpy = text_nyr_y.get()
    xstmpx = text_xs_x.get()
    xstmpy = text_xs_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.press("backspace",10,0.2)
    pg.click()
    pg.hotkey("ctrl", "v")
    pg.moveTo(eval(xstmpx), eval(xstmpy))
    pg.click()
    pg.press("backspace",5,0.2)
    pg.click()
    pg.write("22:00")
    pg.moveTo(180, 150)

def sixfun():
    pg.moveTo(62, 138)
    pg.click()
    tmpx = text_nyr_x.get()
    tmpy = text_nyr_y.get()
    xstmpx = text_xs_x.get()
    xstmpy = text_xs_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.press("backspace",10,0.2)
    pg.click()
    pg.hotkey("ctrl", "v")
    pg.moveTo(eval(xstmpx), eval(xstmpy))
    pg.click()
    pg.press("backspace",5,0.2)
    pg.click()
    pg.write("06:00")
    pg.moveTo(180, 150)
#收缩压与舒张压斜杠--------------------------------------------
def shoushuo():
    tmpx = text_ssy_x.get()
    tmpy = text_ssy_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.press('/')
def shuzhang():
    tmpx = text_szy_x.get()
    tmpy = text_szy_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.press('/')
#收缩压与舒张压斜杠--------------------------------------------


#时间按键函数
def seven():
    sevenfun()
    ysfunction()
    twfuntion()
    mbfunction()
    hxfunction()
    ssyfunction()
    szyfunction()
    xiegang3()
    xiegang2()
    xiegang1()
    xueyangfun()
    xiyangfun()
    zyzfunction()

def fourteen():#14点按键执行
    forutfun()
    ysfunction()
    twfuntion()
    mbfunction()
    hxfunction()
    xiegang3()
    xiegang2()
    xiegang1()
    xueyangfun()
    xiyangfun()
    shuzhang()
    shoushuo()

def eighteen():#18点按键执行
    eightfun()
    ysfunction()
    twfuntion()
    mbfunction()
    hxfunction()
    xiegang3()
    xiegang2()
    xiegang1()
    xueyangfun()
    xiyangfun()
    shuzhang()
    shoushuo()

def twenty_two():#22点按键执行
    tweentyfun()
    ysfunction()
    twfuntion()
    mbfunction()
    hxfunction()
    xiegang3()
    xiegang2()
    xiegang1()
    xueyangfun()
    xiyangfun()
    shuzhang()
    shoushuo()
def six():#6点按键执行
    sixfun()
    ysfunction()
    twfuntion()
    mbfunction()
    hxfunction()
    xiegang3()
    xiegang2()
    xiegang1()
    xueyangfun()
    xiyangfun()
    ssyfunction()
    szyfunction()
    zyzfunction()
def text_copy(temp):
    text_tmp = temp.get()
    pyperclip.copy(text_tmp)

#鼠标位置测试按键
button_test = tk.Button(root,text = "鼠标位置测试",command=test_shubiao, width = 10,font = font,bg="#b1b2b2")
button_test.grid(row=1,column = 1)

tk.Label(root,text="X轴:").grid(row=2,column = 1)
tk.Entry(root,textvariable=testX,width = 10).grid(row=2,column=2)
tk.Label(root,text="Y轴:",width = 10).grid(row=2,column = 3)
tk.Entry(root,textvariable=testY,width = 10).grid(row=2,column=4)
#----------------------------------------------------------

#时间按键组#
button_zhixing7 = tk.Button(root,text="执行07:00",command=seven,width = 10,font=font,bg = "#b1b2b2")
button_zhixing7.grid(row=3,column=1)

button_zhixing14 = tk.Button(root,text="执行14:00",command=fourteen,width = 10,font=font,bg = "#b1b2b2")
button_zhixing14.grid(row=3,column=2)

button_zhixing18 = tk.Button(root,text="执行18:00",command=eighteen,width = 10,font=font,bg = "#b1b2b2")
button_zhixing18.grid(row=3,column=3)

button_zhixing22 = tk.Button(root,text="执行22:00",command=twenty_two,width = 10,font=font,bg = "#b1b2b2")
button_zhixing22.grid(row=3,column=4)

button_zhixing22 = tk.Button(root,text="执行06:00",command=six,width = 10,font=font,bg = "#b1b2b2")
button_zhixing22.grid(row=3,column=5)


#年月日时间位置信息组
#button_nyr = tk.Button(root,text="年月日",command = text_copy,width = 10,font=font,bg = "#b1b2b2")
button_nyr = tk.Button(root,text="年月日",command = lambda:text_copy(text_nyr),width = 10,font=font,bg = "#b1b2b2")
button_nyr.grid(row=4,column=1)
tk.Entry(root,textvariable=text_nyr,width = 15).grid(row=4,column=2)

tk.Label(root,text="年月日X轴:").grid(row=5,column = 1)
tk.Entry(root,textvariable=text_nyr_x,width = 10).grid(row=5,column=2)
tk.Label(root,text="年月日Y轴:",width = 10).grid(row=5,column = 3)
tk.Entry(root,textvariable=text_nyr_y,width = 10).grid(row=5,column=4)

tk.Label(root,text="小时X轴:").grid(row=6,column = 1)
tk.Entry(root,textvariable=text_xs_x,width = 10).grid(row=6,column=2)
tk.Label(root,text="小时Y轴:",width = 10).grid(row=6,column = 3)
tk.Entry(root,textvariable=text_xs_y,width = 10).grid(row=6,column=4)

##填写部分组件
    #意识
def ysfunction():
    tmpx = text_ys.get()
    pyperclip.copy(tmpx)
    tmpx = text_ys_x.get()
    tmpy = text_ys_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.hotkey('ctrl', 'v')

button_ys = tk.Button(root,command=ysfunction,text="意识",width = 10,font=font,bg = "#b1b2b2")
button_ys.grid(row=7,column=1)
tk.Entry(root,textvariable=text_ys,width = 10).grid(row=7,column=2)
tk.Entry(root,textvariable=text_ys_x,width = 10).grid(row=7,column=3)
tk.Entry(root,textvariable=text_ys_y,width = 10).grid(row=7,column=4)


# 体温
def twfuntion():
    tmpx = text_tw.get()
    pyperclip.copy(tmpx)
    tmpx = text_tw_x.get()
    tmpy = text_tw_y.get()
    pg.moveTo(eval(tmpx),eval(tmpy))
    pg.click()
    pg.hotkey('ctrl','v')

button_tw = tk.Button(root,command=twfuntion,text="体温",width = 10,font=font,bg = "#b1b2b2")
button_tw.grid(row=8,column=1)
tk.Entry(root,textvariable=text_tw,width = 10).grid(row=8,column=2)
tk.Entry(root,textvariable=text_tw_x,width = 10).grid(row=8,column=3)
tk.Entry(root,textvariable=text_tw_y,width = 10).grid(row=8,column=4)
#脉搏
def mbfunction():

    tmpx = text_mb.get()
    pyperclip.copy(tmpx)
    tmpx = text_mb_x.get()
    tmpy = text_mb_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.hotkey('ctrl', 'v')

button_mb = tk.Button(root,command=mbfunction,text="脉搏",width = 10,font=font,bg = "#b1b2b2")
button_mb.grid(row=9,column=1)
tk.Entry(root,textvariable=text_mb,width = 10).grid(row=9,column=2)
tk.Entry(root,textvariable=text_mb_x,width = 10).grid(row=9,column=3)
tk.Entry(root,textvariable=text_mb_y,width = 10).grid(row=9,column=4)
#呼吸
def hxfunction():
    tmpx = text_hx.get()
    pyperclip.copy(tmpx)
    tmpx = text_hx_x.get()
    tmpy = text_hx_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.hotkey('ctrl', 'v')

button_hx = tk.Button(root,command=hxfunction,text="呼吸",width = 10,font=font,bg = "#b1b2b2")
button_hx.grid(row=10,column=1)
tk.Entry(root,textvariable=text_hx,width = 10).grid(row=10,column=2)
tk.Entry(root,textvariable=text_hx_x,width = 10).grid(row=10,column=3)
tk.Entry(root,textvariable=text_hx_y,width = 10).grid(row=10,column=4)
#收缩压
def ssyfunction():
    tmpx = text_ssy.get()
    pyperclip.copy(tmpx)
    tmpx = text_ssy_x.get()
    tmpy = text_ssy_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.hotkey('ctrl', 'v')

button_ssy = tk.Button(root,command=ssyfunction,text="收缩压",width = 10,font=font,bg = "#b1b2b2")
button_ssy.grid(row=11,column=1)
tk.Entry(root,textvariable=text_ssy,width = 10).grid(row=11,column=2)
tk.Entry(root,textvariable=text_ssy_x,width = 10).grid(row=11,column=3)
tk.Entry(root,textvariable=text_ssy_y,width = 10).grid(row=11,column=4)
#舒张压
def szyfunction():
    tmpx = text_szy.get()
    pyperclip.copy(tmpx)
    tmpx = text_szy_x.get()
    tmpy = text_szy_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.hotkey('ctrl', 'v')

button_szy = tk.Button(root,command=szyfunction,text="舒张压",width = 10,font=font,bg = "#b1b2b2")
button_szy.grid(row=12,column=1)
tk.Entry(root,textvariable=text_szy,width = 10).grid(row=12,column=2)
tk.Entry(root,textvariable=text_szy_x,width = 10).grid(row=12,column=3)
tk.Entry(root,textvariable=text_szy_y,width = 10).grid(row=12,column=4)
#遵医嘱治疗
def zyzfunction():
    tmpx = text_zyz.get()
    pyperclip.copy(tmpx)
    tmpx = text_zyz_x.get()
    tmpy = text_zyz_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.hotkey('ctrl', 'v')
button_zyz = tk.Button(root,command=zyzfunction,text="遵医嘱",width = 10,font=font,bg = "#b1b2b2")
button_zyz.grid(row=13,column=1)
tk.Entry(root,textvariable=text_zyz,width = 10).grid(row=13,column=2)
tk.Entry(root,textvariable=text_zyz_x,width = 10).grid(row=13,column=3)
tk.Entry(root,textvariable=text_zyz_y,width = 10).grid(row=13,column=4)
    #三个斜杠坐标
def xiegang1():
    tmpx = text_xg1_x.get()
    tmpy = text_xg1_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.press('/')
tk.Label(root,text="斜杠1:").grid(row=14,column = 1)
tk.Entry(root,textvariable=text_xg1_x,width = 10).grid(row=14,column=2)
tk.Entry(root,textvariable=text_xg1_y,width = 10).grid(row=14,column=3)

def xiegang2():
    tmpx = text_xg2_x.get()
    tmpy = text_xg2_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.press('/')
tk.Label(root,text="斜杠2:").grid(row=15,column = 1)
tk.Entry(root,textvariable=text_xg2_x,width = 10).grid(row=15,column=2)
tk.Entry(root,textvariable=text_xg2_y,width = 10).grid(row=15,column=3)
def xiegang3():
    tmpx = text_xg3_x.get()
    tmpy = text_xg3_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.press('/')
tk.Label(root,text="斜杠3:").grid(row=16,column = 1)
tk.Entry(root,textvariable=text_xg3_x,width = 10).grid(row=16,column=2)
tk.Entry(root,textvariable=text_xg3_y,width = 10).grid(row=16,column=3)

def xueyangfun():
    tmpx = text_xueyang_x.get()
    tmpy = text_xueyang_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.press('9')
    pg.press('8')
tk.Label(root,text="血氧:").grid(row=17,column = 1)
tk.Entry(root,textvariable=text_xueyang_x,width = 10).grid(row=17,column=2)
tk.Entry(root,textvariable=text_xueyang_y,width = 10).grid(row=17,column=3)

def xiyangfun():
    tmpx = text_xiyang_x.get()
    tmpy = text_xiyang_y.get()
    pg.moveTo(eval(tmpx), eval(tmpy))
    pg.click()
    pg.press('2')
tk.Label(root,text="吸氧:").grid(row=18,column = 1)
tk.Entry(root,textvariable=text_xiyang_x,width = 10).grid(row=18,column=2)
tk.Entry(root,textvariable=text_xiyang_y,width = 10).grid(row=18,column=3)

root.mainloop()

标签:10,界面,python,text,tk,row,root,pg
From: https://blog.51cto.com/u_16257798/7502498

相关文章

  • python系列教程215——列表解析与矩阵
    声明:在人工智能技术教学期间,不少学生向我提一些python相关的问题,所以为了让同学们掌握更多扩展知识更好地理解AI技术,我让助理负责分享这套python系列教程,希望能帮到大家!由于这套python教程不是由我所写,所以不如我的AI技术教学风趣幽默,学起来比较枯燥;但它的知识点还是讲到位的了,也值......
  • Python编码规范和最佳实践
    Python编码规范和最佳实践是提高代码质量、可读性和可维护性的重要因素。以下将详细介绍Python的编码规范和最佳实践,并通过具体案例说明其功能。Python编码规范文件扩展名Python文件扩展名通常为.py,用于标识Python文件。在命名文件时,应采用简洁、清晰的名称,以反映文件的内容或功能......
  • linux下安装python
    编译安装python3.6的步骤1.下载python3源码包wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz2.下载python3编译的依赖包yuminstall-ygccpatchlibffi-develpython-develzlib-develbzip2-developenssl-develncurses-develsqlite-develreadlin......
  • # yyds干货盘点 #盘点一个Python打包的报错问题
    大家好,我是皮皮。一、前言前几天在Python钻石群【年鱼鱼......
  • python递归求阶乘和
    一些基本概念介绍:阶乘:是指从1到n的连续自然数相乘的积。负数没有阶乘。递归:函数作为一种代码封装,除了被其他程序正常调用外,还可以被函数内部代码调用。函数定义中调用函数自身的方式称为递归。递归实现的两个关键点:(1)存在一个或多个基例,基例不需要再次递归,它是确定的表达式。否则......
  • 基于Python的鲜花在线销售系统-计算机毕业设计源码+LW文档
    摘 要随着信息技术的发展,基于web模式的购物系统逐渐普及,网上购物是一种新型的商务模式,其工作流程和经营模式受到了欢迎。电子商务可以适应现代化快节奏的生活方式,满足各类人群足不出户的在线购物,利用商城使得买卖双方完成线上交易,提高了购买效率。然而像鲜花这种传统的行业,由于......
  • Python第五章(1)字符串
    1.字符串的特性:(1)字符串是不可变类型。2.字符串的判定:isinstance(testString,str)3.用三引号实现长字符串。当开头的"""\时,开头不会输出换行符。4.字符串的索引和切片(1)字符串索引在实际使用情况下,“索引值”即“偏移量”。aString=="你好......
  • python实现从网站下载文件, 带进度信息
    我实现了一个函数,代码如下:defdownload_file_from_url(url,save_path='',callback:callable=None):'''下载文件,并保存到save_path指定的位置url:形如'http://www.tdx.com.cn/products/data/data/vipdoc/shlday.zip'或者'http......
  • python之爬虫requests
    importrequestsresult=requests.get("https://127.0.0.1:9200/_search",headers=headers,verify=False)#verify跳过ssl认证关于http的authorization认证......
  • python数据类型
    数据类型整数、浮点、字符串、布尔、列表、元组、字典、集合整数int(integer)字面意思就是整数,定义时不要加引号,否则会变成字符串浮点float理解为小数点,定义时不要加引号,否则会变成字符串字符串在python中加了引号的都会被认为是字符串 ......