Python Tkinter序列形式传递参数

问题描述 投票:-1回答:1

我是Python编程的新手,对一个问题有些困惑。

我正在试图构建一系列表格并将参数从一种表格传递到下一种表格。尽管我找到了显示如何在表单之间进行切换的示例,但还没有找到显示不同类之间的表单之间传递参数的示例。

下面的代码是错误的,并且有错误-很抱歉。我认为这对于有经验的Python程序员来说相对来说比较容易。感谢您在此问题上的帮助和考虑。

# Problem 1: All forms open at once instead of 1 at a time
#         2: The buttons are not attached to the forms
#         3: Not sure if parameters are being passed from Form1 to Form2
#         4: Now i am getting errors
# Notes: All forms will be different sizes

import tkinter as tk

class Form1(tk.Tk):
    def __init__(self, master):
        two=tk.Tk() # <--define object for Form2
        value1 = 'Some Text'
        value2 = 8
        value3 = 'More Text'
        #--attempting to pass 3 parameters to Form2
        #---on click, open Form2  and close Form1
        self.btn=tk.Button(self,text='button 1',
                           command=Form2.__init__(two, value1, value2, value3))
        self.btn.grid(row=0,column=0)

class Form2(tk.Tk):
   def  __init__(self, parm1, parm2, parm3):
        print(parm1, parm2, parm3)

        three=tk.Tk() # <--define object for Form3
        #---on click, open Form3 form and close Form2
        self.btn=tk.Button(self,text='button 2', command=Form3.__init__(three))
        self.btn.grid(row=0,column=0)

class Form3(tk.Tk):
    def __init__(self):
        three = tk.Tk()
        self.btn=tk.Button(self,text='button3 ',command=None) # action to be added later
        self.btn.grid(row=0,column=0)

a=tk.Tk()
Form1 = Form1(a)
python tkinter parameter-passing
1个回答
0
投票

感谢那些花时间发表评论的人。我使用人们发布的其他示例中的构想重新编写了该程序。现在可以使用,但是在达到目的后仍需要隐藏窗口的方法。

© www.soinside.com 2019 - 2024. All rights reserved.