python - 来自 tkinter 和页面上的按钮的新窗口
问题描述
大家好,我正在使用页面为我的项目创建 gui;但是当我尝试使用按钮从窗口 1 打开窗口 2 时,将其作为参数 main 或 rot 在其中,它不会显示为错误 main未定义
在一个单独的python文件中,我有图形界面,在另一个python文件中,我有一个图形界面,必须通过按钮打开第一个文件中存在的另一个界面,我在第二个文件中导入了第一个文件的功能并读取创建函数;但是当我必须使用函数 create_toplevel1 将它作为参数作为第一个窗口退出的主窗口时,它告诉我它没有定义,对于 root 也是一样,并且没有参数是不可能的,因为函数必须接受一个参数
#first main when I click the button and appear the second window
class AdminPanel:
def __init__(self, top=None):
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
self.btnregutenti =tk.Button(top,command=create_TopLevel1(root))
def create_AdminPanel(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = tk.Toplevel (root)
top = AdminPanel (w)
return (w, top)
#second window that appear when I use a button
def create_TopLevel1(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = tk.Toplevel (root)
top = TopLevel1 (w)
# user_interface_support.init(w, top, *args, **kwargs)
return (w, top)
在本指令中 self.btnregutenti=tk.Button(top,command=create_TopLevel1(root))
我应该插入什么参数来显示正确的窗口?
解决方案
问题是 Button 将函数作为command=
参数值。通过使用tk.Button(top,command=create_TopLevel1(root))
,您已经在调用该函数。您应该改为使用tk.Button(top,command=create_TopLevel1)
和编辑create_TopLevel1
,因此它不需要任何参数。希望这会有所帮助!
推荐阅读
- python - 我使用了 Serpapi 谷歌地图抓取代码,但它给了我一个回溯错误
- mysql - MySQL 反向工程仅具有数据的表
- docker - docker compose 无法访问其他容器的端口
- python-3.x - [0,1,2,3,4] 和 [[0],[1],[2],[3],[4]] 有什么区别?
- postgresql - 在 Postgres 中具有类型转换的 JSONB 字段的部分索引
- python - “pyinstaller game.py”工作正常,但 --onefile 不行。(我不能有任何依赖,因为没有 --onefile 就可以工作)
- javascript - JavaScript 库 SheetJS。将字符串传递给excel parce函数
- gekko - Gekko 长期性能
- javascript - 如何将一组日期范围分组为具有最小时间间隔的较小组?
- c# - 将命令行参数传递给 C# .NET 应用程序而不使用 UWP 应用程序内的清单文件