我有一个python程序,它打开一个新窗口来显示一些"关于"信息.这个窗口有自己的关闭按钮,我已经使它不可调整大小.然而,最大化和最小化它的按钮仍然存在,我希望它们消失.
我正在使用Tkinter,包装所有信息以显示在Tk类中.
到目前为止的代码如下.我知道它不漂亮,我打算扩展信息使其成为一个类,但我希望在移动之前对此问题进行排序.
任何人都知道如何管理Windows管理器显示哪些默认按钮?
def showAbout(self):
if self.aboutOpen==0:
self.about=Tk()
self.about.title("About "+ self.programName)
Label(self.about,text="%s: Version 1.0" % self.programName ,foreground='blue').pack()
Label(self.about,text="By Vidar").pack()
self.contact=Label(self.about,text="Contact: adress@gmail.com",font=("Helvetica", 10))
self.contact.pack()
self.closeButton=Button(self.about, text="Close", command = lambda: self.showAbout())
self.closeButton.pack()
self.about.geometry("%dx%d+%d+%d" % (175,\
95,\
self.myParent.winfo_rootx()+self.myParent.winfo_width()/2-75,\
self.myParent.winfo_rooty()+self.myParent.winfo_height()/2-35))
self.about.resizable(0,0)
self.aboutOpen=1
self.about.protocol("WM_DELETE_WINDOW", lambda: self.showAbout())
self.closeButton.focus_force()
self.contact.bind('<Leave>', self.contactMouseOver)
self.contact.bind('<Enter>', self.contactMouseOver)
self.contact.bind('<Button-1>', self.mailAuthor)
else:
self.about.destroy()
self.aboutOpen=0
def contactMouseOver(self,event):
if event.type==str(7):
self.contact.config(font=("Helvetica", 10, 'underline'))
elif event.type==str(8):
self.contact.config(font=("Helvetica", 10))
def mailAuthor(self,event):
import webbrowser
webbrowser.open('mailto:adress@gmail.com',new=1)
Run Code Online (Sandbox Code Playgroud) 错误: ImportError:导入 _ctypes 时 DLL 加载失败:找不到指定的模块
Need: How to resolve this error? And launch jupyter notebook and use pip from the specific environment? It works on other environment.
While trying to launch jupyter notebook or using pip in virtual environment. I couldn't launch jupyter in the environment "Myenvproject". It launches on the base environment.
I tried to
conda uninstall pyzmq
In the environment.
And reinstall jupyter in "Myenvproject" Environment but it still doesn't launch. Jupyter doesn't launch
Turns out that …
问题
我正在使用 Windows 11 操作系统上的受阻窗口捕获屏幕截图windll.user32.PrintWindow(这又WM_PRINT根据文档进行调用)。一切都按预期工作,但是从 Windows 10 迁移到 Windows 11 后,性能非常不稳定。在 Win10 上,捕获通常需要不到 30 毫秒,在 Win11 上,有时接近这个时间,但有时屏幕捕获将持续数小时重复接近 300 毫秒(屏幕捕获在循环中运行)。在Win10上运行屏幕截图的几个月里从未出现过这种情况。造成这种缓慢性能的单行代码是对PrintWindow.
有趣的是,只有在捕获特定应用程序时才会出现性能缓慢的情况。这是一个第三方应用程序,我没有它的源代码,我只知道它使用Java。当尝试使用相同的屏幕捕获代码捕获其他应用程序时,性能符合预期 - 大约 20-30 毫秒。
附加信息
(WM_PRINT打印整个窗口和仅打印客户区域或)的时间大致相同WM_PRINTCLIENT。
时间与捕获窗口的大小呈线性关系。对于其他应用程序而言,情况并非如此 - PrintWindow 花费的时间大致相同(大约 30 毫秒),无论捕获的窗口是否占据全屏或尺寸是否大幅减小。
速度较慢的计算机(i5 9600 12 GB RAM)和较快的计算机(i7 10700 32 GB RAM)都会出现性能缓慢的情况。使用速度较慢的 PC 在 Win10 上运行屏幕捕获(捕获时间不到 30 毫秒)。
当性能变慢时,CPU 和 GPU 不会负担过重(查看任务管理器,它们的使用率不到 3%)。我没有注意到任何关于它何时变慢的模式。
动画的操作系统设置已关闭。另外,窗口没有最小化和恢复,所以据我了解,动画不应该是一个因素。
在捕获的应用程序中添加控件时,屏幕捕获会稍微变慢。然而,将控件减少到最低限度仍然无法让我接近所需的 30 毫秒捕获时间。
我最初的猜测:
操作系统对CPU/GPU要求过高。我认为在 i7 10700 上进行的测试与 i5 上的结果相同,证明情况并非如此。
应用程序的消息队列可能负载过重,并且我的 PrintWindow 调用正在排队等待。我认为性能随窗口大小线性缩放表明情况并非如此。我还尝试在调用 PrintWindow 之前调用 …
我的proj1.dll它依赖于另一个 DLL proj2.dll,. 我是proj1.dll针对VS2013中编译时编译器输出的导入库进行编译的proj2.dll。我还导出了我有兴趣使用的公共函数。所以现在我有两个独立的 DLL,它们都符合“cdll”标准。
我想在 Python 中使用proj1.dll,但遇到以下问题:
import ctypes
# Crashes saying no entry point for "some_func" in proj2.dll
ctypes.cdll.LoadLibrary("C:\myfolder\proj1.dll")
ctypes.cdll.LoadLibrary("C:\myfolder\proj2.dll") # Loads fine
ctypes.cdll.LoadLibrary("C:\myfolder\proj1.dll") # Loads fine if proj2 is loaded first
Run Code Online (Sandbox Code Playgroud)
以前,当我构建proj2为静态库并在proj1. 这两个 DLL 存在于同一文件夹中。我什至尝试将文件夹的路径添加到我的 PATH 环境变量中,以查看这是否是路径问题,但没有任何改变。
我假设 Windows 将加载proj1.dll然后加载 dll 的依赖项。我错了吗?调用者(Python)是否必须首先加载依赖DLL?有谁知道为什么会发生这种情况?
这两种方法似乎都有效(对我来说),但似乎该CDLL()方法返回一个具有_handle属性的对象,该对象可用于通过ctypes.windll.kernel32.FreeLibrary()(至少在 Windows 上卸载库 - 我还不知道如何在 Linux 上执行此操作) )。
这两种方法有什么区别 - 为什么我要选择其中一种而不是另一种?
最终,我的目标是能够在 Linux 和 Windows 上加载和卸载库(因为我有一个第三方库,有时似乎会进入损坏状态 - 我希望卸载/重新加载能够重置它)。
我有以下代码
import ctypes
lib1 = ctypes.cdll.LoadLibrary("./mylib.so")
# modify mylib.so (code generation and compilation) or even delete it
lib2 = ctypes.cdll.LoadLibrary("./mylib.so")
Run Code Online (Sandbox Code Playgroud)
问题是lib2指的是原始共享库,而不是新共享库。如果我在调用之间删除 mylib.so ,则不会出现错误。
使用ctypes._reset_cache()没有帮助。
我如何判断ctypes是否真正从硬盘重新加载库?
有没有办法使用Python Windows 扩展来获取窗口的 z 顺序?或者,有没有办法使用另一个模块来做到这一点?通常的方法是使用GetTopWindowand GetNextWindow,但这些函数都没有出现在win32gui模块中。
目前我正在这样做,但它没有考虑到 Windows 的 z 顺序:
import win32gui
def get_windows():
def callback(hwnd, lst):
lst.append(hwnd)
lst = []
win32gui.EnumWindows(callback, lst)
return lst
Run Code Online (Sandbox Code Playgroud)
理想情况下,我想要这样的东西:(这不起作用)
import win32gui
import win32con
def get_windows():
'''Returns windows in z-order (top first)'''
lst = []
top = win32gui.GetTopWindow()
if top is None: return lst
lst.append(top)
while True:
next = win32gui.GetNextWindow(lst[-1], win32con.GW_HWNDNEXT)
if next is None: break
lst.append(next)
return lst
Run Code Online (Sandbox Code Playgroud)
但是,缺少GetTopWindow和GetNextWindow功能,所以我不能。
更新:
我想我寻求帮助的速度有点太快了。我用 …