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="请选择账号:").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(0.01) # 等待界面加载 pyautogui.click(952, 495) pyautogui.typewrite(password) pyautogui.press('enter') root.destroy() # 创建登录按钮 tk.Button(root, text="登录", command=login).grid(row=len(options)+1, column=0, pady=10) root.mainloop() # 切换到登录界面 pyautogui.hotkey('alt', 'tab'),帮我修改一下代码
时间: 2023-11-13 07:05:03 浏览: 146
好的,我看到你的代码中有一个问题,就是在使用 `subprocess.Popen()` 打开 Internet Explorer 时,路径的反斜杠需要使用转义符号,否则会报错。下面是修改后的代码:
```python
import pyautogui
import time
import tkinter as tk
import subprocess
# 用 subprocess 打开 Internet Explorer
subprocess.Popen(r'C:\Program Files\Internet Explorer\iexplore.exe')
# 创建 GUI 界面
root = tk.Tk()
root.title("选择账号")
# 创建标签和选项
tk.Label(root, text="请选择账号:").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(0.01) # 等待界面加载
pyautogui.click(952, 495)
pyautogui.typewrite(password)
pyautogui.press('enter')
root.destroy()
# 创建登录按钮
tk.Button(root, text="登录", command=login).grid(row=len(options)+1, column=0, pady=10)
root.mainloop()
# 切换到登录界面
pyautogui.hotkey('alt', 'tab')
```
我添加了一个 `r` 前缀来表示原始字符串,这样反斜杠就不需要转义了。
阅读全文