在使用tkinter制作多选窗口时,在本地3.7.1版本的python中是正常运行的,在Uibot中就报错

哈士奇! 1月前 146

import tkinter as tk
def show_dialog():
    choices = ['采集出库信息', '设计单位表格处理', '施工单位表格处理']
    selected_values = []
    def on_confirm_click():
        for idx, var in enumerate(vars):
            if var.get() == 1:
                selected_values.append(choices[idx])
        root.destroy() 
    def on_cancel_click():
        root.destroy()
    
    def on_close():
        root.destroy()
    
    root = tk.Tk()
    root.title("请选择功能(可多选)")
    root.iconbitmap('tb.ico')
    window_width = 300
    window_height = 200
    
    screen_width = root.winfo_screenwidth()
    screen_height = root.winfo_screenheight()
    
    x = (screen_width - window_width) // 2
    y = (screen_height - window_height) // 2
    
    root.geometry(f"{window_width}x{window_height}+{x}+{y}")
    
    vars = []
    frame = tk.Frame(root)
    frame.pack(pady=20)
    for choice in choices:
        var = tk.IntVar()
        vars.append(var)
        checkbox = tk.Checkbutton(frame, text=" " + choice, variable=var)
        checkbox.pack(anchor=tk.W)
    confirm_button = tk.Button(root, text="确认", command=on_confirm_click)
    confirm_button.place(relx=0.5, rely=0.9, anchor=tk.CENTER, x=-50)
    cancel_button = tk.Button(root, text="取消", command=on_cancel_click)
    cancel_button.place(relx=0.5, rely=0.9, anchor=tk.CENTER, x=50)
    root.protocol("WM_DELETE_WINDOW", on_close)
    root.mainloop()
    
    if selected_values:
        return selected_values
    else:
        selected_values=False
        return  selected_values
result = show_dialog()
print(result)

插件命为:ais.py
库放置在流程的extend/python/ais.lib文件夹下。
运行import ais时报错:module 'tkinter' has no attribute 'Tk'。是我放错了还是这个Uibot不支持这个库。
这个python库是内置在python中的,但在Uibot根目录的lib/site-packages下没有这个库。

想知道是我自己存放的方法不对,还是Uibot不支持这个python库

最新回复 (2)
  • rainvale 1月前
    2
    库放到创建的流程工程文件夹内的extend/python里面
  • 哈士奇! 1月前
    3
    rainvale 库放到创建的流程工程文件夹内的extend/python里面
    已经解决了,应该是Uibot不行,我用的是企业版的5.5.5 32位的。我把代码封装成exe可执行文件了,然后通过另外一个库来调用了这个可执行文件返回参数,已经可以用了。
返回
发新帖