python - 导入 pyautogui 会改变 tkinter 的大小
问题描述
我有一个 tkiner 框架,里面有几个按钮。我想将这些按钮之一绑定到 pyautogui 脚本,但是导入但不实现 pyautogui 的行为会改变我所有按钮、复选框和选项菜单的大小。它发生在此窗口和所有子窗口中。
为什么会发生这种情况,我怎样才能让我的按钮保持相同的大小?下面的代码复制了这个问题。
from tkinter import *
#import pyautogui # comment out to see normal sized
# buttons, include to see issue
class mywindow(Frame):
def __init__(self, master, *pargs):
Frame.__init__(self, master, *pargs)
master.overrideredirect(1)
self.frame = Frame(master, width=50, height=200,
borderwidth=2, relief=RAISED)
self.frame.grid(row=0,column=0)
self.bg = Label(self.frame, bg='gray30', width=50, height=200, anchor=E)
self.bg.pack()
self.mybutton1 = Button(self.bg, text="my text",
command=self.mycommand)
self.mybutton1.grid(row=0,sticky=W+E+N+S)
self.mybutton2 = Button(self.bg, text="my text",
command=self.mycommand)
self.mybutton2.grid(row=1,sticky=W+E+N+S)
self.mybutton3 = Button(self.bg, text="my text",
command=self.mycommand)
self.mybutton3.grid(row=2,sticky=W+E+N+S)
def mycommand(self):
pass
def center_window(root, width, height):
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x = (screen_width/2) - (width)
y = (screen_height/2) - (height)
root.geometry('%dx%d+%d+%d' % (width, height, x, y))
def go():
root = Tk()
center_window(root, 70, 110)
e = mywindow(root)
root.mainloop()
if __name__ == '__main__':
go()
解决方案
推荐阅读
- bash - 在 github 操作中安装 npm 模块
- powerbi - PowerBI中的单选按钮的行基计算
- alexa - 如何在 Alexa Skills 中动态设置 Slot 值?
- css - 使用样式化组件按类名更改 css 样式
- javascript - javascript - 堆栈问题?
- javascript - 从 vue.js 中的单选按钮循环中取消选中单个单选按钮
- sap-cloud-sdk - 通过 odata-generator-cli 创建 OData 客户端时出现异常
- java - 如何在 Spring MVC 中的 Redirect 中传递对象?
- html - 如何在 CSS 中打破报纸样式 3 列布局?
- php - 在 php 类中定义一个全局变量