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

用python的tk写一个界面_tkinter

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()
阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: python