import pyautogui import time import tkinter as tk import subprocess # 用subprocess打开Internet Explorer subprocess.Popen('C:\Program Files\Internet Explorer\iexplore.exe') # 创建 GUI 界面 root = tk.Tk() root.title("选择账号") # 创建标签和选项 tk.Label(root, text="用IE打开HIS系统,请选择账号:").grid(row=0, column=0, sticky=tk.W, padx=10, pady=10) options = [ ("马家益", "tb021 A123456"), ("王中豪", "tb121 A123456"), ("陈诗源", "tb058 A123456"), ("陈亮", "tb057 12345678"), ("张少芬", "tb017 A123456"), ("海玲", "tb020 A123456"), ("张科", "tb090 Tbyy123456@"), ("邱进东", "tb110 A123456"), ("黎福妮", "tb095 HD@123456"), ("任国军", "tb051 HD@123456"), ("叶穗君", "tb032 A*123456") ] var = tk.StringVar() var.set("") # 设置默认值为空 for i, option in enumerate(options): tk.Radiobutton(root, text=option[0], variable=var, value=option[1]).grid(row=i+1, column=0, sticky=tk.W, padx=10, pady=5) # 创建登录按钮的函数 def login(): # 获取选择的账号和密码 choice = var.get() if not choice: tk.messagebox.showwarning("警告", "请选择一个账号!") return username, password = choice.split() # 单击左键并输入账号 pyautogui.click(843, 440) pyautogui.typewrite(username) # 单击左键并输入密码,然后按回车键 time.sleep(1) # 等待界面加载 pyautogui.click(952, 495) pyautogui.typewrite(password) pyautogui.press('enter') # 创建登录按钮 tk.Button(root, text="登录", command=login).grid(row=len(options)+1, column=0, pady=10) root.mainloop(),帮我默认设置成陈亮选项
时间: 2023-07-19 13:10:40 浏览: 120
import tkinter.py
你可以将以下代码添加到程序的最后几行,这样默认选中陈亮选项:
```
var.set("tb057 12345678")
```
完整代码如下:
```
import pyautogui
import time
import tkinter as tk
import subprocess
# 用subprocess打开Internet Explorer
subprocess.Popen('C:\Program Files\Internet Explorer\iexplore.exe')
# 创建 GUI 界面
root = tk.Tk()
root.title("选择账号")
# 创建标签和选项
tk.Label(root, text="用IE打开HIS系统,请选择账号:").grid(row=0, column=0, sticky=tk.W, padx=10, pady=10)
options = [
("马家益", "tb021 A123456"),
("王中豪", "tb121 A123456"),
("陈诗源", "tb058 A123456"),
("陈亮", "tb057 12345678"),
("张少芬", "tb017 A123456"),
("海玲", "tb020 A123456"),
("张科", "tb090 Tbyy123456@"),
("邱进东", "tb110 A123456"),
("黎福妮", "tb095 HD@123456"),
("任国军", "tb051 HD@123456"),
("叶穗君", "tb032 A*123456")
]
var = tk.StringVar()
var.set("tb057 12345678") # 设置默认值为陈亮选项
for i, option in enumerate(options):
tk.Radiobutton(root, text=option[0], variable=var, value=option[1]).grid(row=i+1, column=0, sticky=tk.W, padx=10, pady=5)
# 创建登录按钮的函数
def login():
# 获取选择的账号和密码
choice = var.get()
if not choice:
tk.messagebox.showwarning("警告", "请选择一个账号!")
return
username, password = choice.split()
# 单击左键并输入账号
pyautogui.click(843, 440)
pyautogui.typewrite(username)
# 单击左键并输入密码,然后按回车键
time.sleep(1) # 等待界面加载
pyautogui.click(952, 495)
pyautogui.typewrite(password)
pyautogui.press('enter')
# 创建登录按钮
tk.Button(root, text="登录", command=login).grid(row=len(options)+1, column=0, pady=10)
root.mainloop()
```
阅读全文