使用TKINTER Python3:如何在同一个gui中将输入信息显示到另一个文本/显示框中?

时间:2018-03-20 19:49:16

标签: python-3.x tkinter tkinter-entry

我想在gui中将输入的文本显示在同一个gui中的另一个框区域中。 我将展示一张照片,希望能够理解我的问题。

我正在尝试发布整个代码段,但此站点有太多规则。

这是我想要做的图像。 SEE MY EXAMPLE IMAGE HERE 这是我的开发代码:

        from Tkinter import *
    import io
    import math

    DB_OS_TYPE = """DB_OS_TYPE
    1 Help stuff here 

    """

    VERSION = """VERSION
    2 Help stuff here

    """

    STAGE_DEPLOY = """STAGE_DEPLOY
    3. Help stuff here

    """

    USECASE = """USECASE
    4 Help stuff here

    """

    R_nonR = """R_nonR
    5 Help stuff here

    """

    S_or_T = """S_or_T
    6 Help stuff here

    """

    INT_CLASS = """INT_CLASS
    7 Help stuff here

    """

    C_NAME = """C_NAME
    8 Help stuff here

    """

    P_NAME = """P_NAME
    9 Help stuff here

    """

    INSTALL_LOC = """INSTALL_LOC
    10 Help stuff here

    """

    O_HOME = """O_HOME
    11 Help stuff here

    """
    PRIMARY_E = """PRIMARY_E
    12 Help Stuff Here

    """

    PMP = """PMP
    13 Help stuff here

    """

    REPL = """REPL
    14 Help stuff here

    """

    PORT = """PORT
    15 Help stuff here

    """

    PORT_LIST = """PORT_LIST
    16 Help stuff here

    """

    def clickAbout1():
        toplevel = Toplevel()
        help_label1 = Label(toplevel, text=DB_OS_TYPE, height=0, width=90, justify=LEFT, anchor='w')
        help_label1.pack()

    def clickAbout2():
        toplevel = Toplevel()
        help_label2 = Label(toplevel, text=VERSION, height=0, width=90, justify=LEFT, anchor='w')
        help_label2.pack()

    def clickAbout3():
        toplevel = Toplevel()
        help_label3= Label(toplevel, text=STAGE_DEPLOY, height=0, width=90, justify=LEFT, anchor='w')
        help_label3.pack()

    def clickAbout4():
        toplevel = Toplevel()
        help_label4= Label(toplevel, text=USECASE, height=0, width=90, justify=LEFT, anchor='w')
        help_label4.pack()

    def clickAbout5():
        toplevel = Toplevel()
        help_label5= Label(toplevel, text=R_nonR, height=0, width=90, justify=LEFT, anchor='w')
        help_label5.pack()

    def clickAbout6():
        toplevel = Toplevel()
        help_label6= Label(toplevel, text=S_or_T, height=0, width=90, justify=LEFT, anchor='w')
        help_label6.pack()

    def clickAbout7():
        toplevel = Toplevel()
        help_label7= Label(toplevel, text=INT_CLASS, height=0, width=90, justify=LEFT, anchor='w')
        help_label7.pack()

    def clickAbout8():
        toplevel = Toplevel()
        help_label8= Label(toplevel, text=C_NAME, height=0, width=90, justify=LEFT, anchor='w')
        help_label8.pack()

    def clickAbout9():
        toplevel = Toplevel()
        help_label9= Label(toplevel, text=P_NAME, height=0, width=90, justify=LEFT, anchor='w')
        help_label9.pack()

    def clickAbout10():
        toplevel = Toplevel()
        help_label10= Label(toplevel, text=INSTALL_LOC, height=0, width=90, justify=LEFT, anchor='w')
        help_label10.pack()

    def clickAbout11():
        toplevel = Toplevel()
        help_label11= Label(toplevel, text=O_HOME, height=0, width=90, justify=LEFT, anchor='w')
        help_label11.pack()

    def clickAbout12():
        toplevel = Toplevel()
        help_label12= Label(toplevel, text=PRIMARY_E, height=0, width=90, justify=LEFT, anchor='w')
        help_label12.pack()    

    def clickAbout13():
        toplevel = Toplevel()
        help_label13= Label(toplevel, text=PMP, height=0, width=90, justify=LEFT, anchor='w')
        help_label13.pack()

    def clickAbout14():
        toplevel = Toplevel()
        help_label14= Label(toplevel, text=REPL, height=0, width=90, justify=LEFT, anchor='w')
        help_label14.pack()

    def clickAbout15():
        toplevel = Toplevel()
        help_label15= Label(toplevel, text=PORT, height=0, width=90, justify=LEFT, anchor='w')
        help_label15.pack()

    def clickAbout16():
        toplevel = Toplevel()
        help_label16= Label(toplevel, text=PORT_LIST, height=0, width=90, justify=LEFT, anchor='w')
        help_label16.pack()

    def loadme(self):
        path = 'my-summary'
        path_file1 = open(path, 'r')
        path_file2 = path_file1.read()

    class ComputeAaa:
        def __init__(self, master):
            self.aaa_frame1 = Frame(master)
            self.aaa_frame1.pack()

            self.aaa_status_label1 = Label(self.aaa_frame1, text="1. DB/OS type:")
            self.aaa_status_label1.grid(row=0, column=0, sticky=W)
            self.aaa_status_option1 = StringVar(self.aaa_frame1)
            self.aaa_status_option1.set("1 example")
            self.aaa_status_option1a = OptionMenu(self.aaa_frame1, self.aaa_status_option1, "1 example", "2 example", "3 example", "4 example", "5 example", "6 example", "None")
            self.aaa_status_option1a.grid(row=0, column=1, sticky=W)
            button1 = Button(self.aaa_frame1, text="1. ?", width=2, command=clickAbout1)
            button1.grid(row=0, column=1)

            self.aaa_status_label2 = Label(self.aaa_frame1, text="2. Your version:")
            self.aaa_status_label2.grid(row=2, column=0, sticky=W)
            self.aaa_status_option2 = StringVar(self.aaa_frame1)
            self.aaa_status_option2.set("1 example")
            self.aaa_status_option2a = OptionMenu(self.aaa_frame1, self.aaa_status_option2, "1 example", "2 example", "3 example", "4 example", "None")
            self.aaa_status_option2a.grid(row=2, column=1, sticky=W)
            button2 = Button(self.aaa_frame1, text="2. ?", width=2, command=clickAbout2)
            button2.grid(row=2, column=1)

            self.aaa_status_label3 = Label(self.aaa_frame1, text="3. Stage or Deploy:")
            self.aaa_status_label3.grid(row=3, column=0, sticky=W)
            self.aaa_status_option3 = StringVar(self.aaa_frame1)
            self.aaa_status_option3.set("1 example")
            self.aaa_status_option3a = OptionMenu(self.aaa_frame1, self.aaa_status_option3, "1 example", "2 example")
            self.aaa_status_option3a.grid(row=3, column=1, sticky=W)
            button3 = Button(self.aaa_frame1, text="3. ?", width=2, command=clickAbout3)
            button3.grid(row=3, column=1)

            self.aaa_status_label4 = Label(self.aaa_frame1, text="4. UseCase:")
            self.aaa_status_label4.grid(row=4, column=0, sticky=W)
            self.aaa_status_option4 = StringVar(self.aaa_frame1)
            self.aaa_status_option4.set("1 example")
            self.aaa_status_option4a = OptionMenu(self.aaa_frame1, self.aaa_status_option4, "1 example", "2 example")
            self.aaa_status_option4a.grid(row=4, column=1, sticky=W)
            button4 = Button(self.aaa_frame1, text="4. ?", width=2, command=clickAbout4)
            button4.grid(row=4, column=1)

            self.aaa_status_label5 = Label(self.aaa_frame1, text="5. R or NON-R:")
            self.aaa_status_label5.grid(row=5, column=0, sticky=W)
            self.aaa_status_option5 = StringVar(self.aaa_frame1)
            self.aaa_status_option5.set("1 example")
            self.aaa_status_option5a = OptionMenu(self.aaa_frame1, self.aaa_status_option5, "1 example", "2 example")
            self.aaa_status_option5a.grid(row=5, column=1, sticky=W)
            button5 = Button(self.aaa_frame1, text="5. ?", width=2, command=clickAbout5)
            button5.grid(row=5, column=1)

            self.aaa_status_label6 = Label(self.aaa_frame1, text="6. S or T:")
            self.aaa_status_label6.grid(row=6, column=0, sticky=W)
            self.aaa_status_option6 = StringVar(self.aaa_frame1)
            self.aaa_status_option6.set("example 1")
            self.aaa_status_option6a = OptionMenu(self.aaa_frame1, self.aaa_status_option6, "1 example", "2 example")
            self.aaa_status_option6a.grid(row=6, column=1, sticky=W)
            button6 = Button(self.aaa_frame1, text="6. ?", width=2, command=clickAbout6)
            button6.grid(row=6, column=1)   

            self.aaa_status_label7 = Label(self.aaa_frame1, text="7. Install Type:")
            self.aaa_status_label7.grid(row=7, column=0, sticky=W)
            self.aaa_status_option7 = StringVar(self.aaa_frame1)
            self.aaa_status_option7.set("1 example")
            self.aaa_status_option7a = OptionMenu(self.aaa_frame1, self.aaa_status_option7, "1 example", "2 example")
            self.aaa_status_option7a.grid(row=7, column=1, sticky=W)
            button7 = Button(self.aaa_frame1, text="7. ?", width=3, command=clickAbout7)
            button7.grid(row=7, column=1)

            self.aaa_label8 = Label(self.aaa_frame1, text="8. C Name:")
            self.aaa_label8.grid(row=10, column=0, sticky=W)
            self.aaa_input8 = StringVar(self.aaa_frame1)
            self.aaa_input8 = Entry(self.aaa_frame1, textvariable=self.aaa_input8, width=60)
            self.aaa_input8.grid(row=10, column=1, sticky=W)
            button8 = Button(self.aaa_frame1, text="8. ?", width=3, command=clickAbout8)
            button8.grid(row=10, column=2)

            self.aaa_label9 = Label(self.aaa_frame1, text="9. P Name:")
            self.aaa_label9.grid(row=11, column=0, sticky=W)
            self.aaa_input9 = StringVar(self.aaa_frame1)
            self.aaa_input9 = Entry(self.aaa_frame1, textvariable=self.aaa_input9, width=60)
            self.aaa_input9.grid(row=11, column=1, sticky=W)
            button9 = Button(self.aaa_frame1, text="9. ?", width=3, command=clickAbout9)
            button9.grid(row=11, column=2)        

            self.aaa_label10 = Label(self.aaa_frame1, text="10. Install location:")
            self.aaa_label10.grid(row=12, column=0, sticky=W)
            self.aaa_input10 = StringVar(self.aaa_frame1)
            self.aaa_input10 = Entry(self.aaa_frame1, textvariable=self.aaa_input10, width=60)
            self.aaa_input10.grid(row=12, column=1, sticky=W)
            button10 = Button(self.aaa_frame1, text="10. ?", width=3, command=clickAbout10)
            button10.grid(row=12, column=2)

            self.aaa_label11 = Label(self.aaa_frame1, text="11. Path1:")
            self.aaa_label11.grid(row=13, column=0, sticky=W)
            self.aaa_input11 = StringVar(self.aaa_frame1)
            self.aaa_input11 = Entry(self.aaa_frame1, textvariable=self.aaa_input11, width=60)
            self.aaa_input11.grid(row=13, column=1, sticky=W)
            button11 = Button(self.aaa_frame1, text="11. ?", width=3, command=clickAbout11)
            button11.grid(row=13, column=2)

            self.aaa_label12 = Label(self.aaa_frame1, text="12. Pri Name:")
            self.aaa_label12.grid(row=14, column=0, sticky=W)
            self.aaa_input12 = StringVar(self.aaa_frame1)
            self.aaa_input12 = Entry(self.aaa_frame1, textvariable=self.aaa_input12, width=60)
            self.aaa_input12.grid(row=14, column=1, sticky=W)
            button12 = Button(self.aaa_frame1, text="12. ?", width=3, command=clickAbout12)
            button12.grid(row=14, column=2)

            self.aaa_label13 = Label(self.aaa_frame1, text="13. P Name:")
            self.aaa_label13.grid(row=15, column=0, sticky=W)
            self.aaa_input13 = StringVar(self.aaa_frame1)
            self.aaa_input13 = Entry(self.aaa_frame1, textvariable=self.aaa_input13, width=60)
            self.aaa_input13.grid(row=15, column=1, sticky=W)
            button13 = Button(self.aaa_frame1, text="13. ?", width=3, command=clickAbout13)
            button13.grid(row=15, column=2)

            self.aaa_label14 = Label(self.aaa_frame1, text="14. Repl Name:")
            self.aaa_label14.grid(row=16, column=0, sticky=W)
            self.aaa_input14 = StringVar(self.aaa_frame1)
            self.aaa_input14 = Entry(self.aaa_frame1, textvariable=self.aaa_input14, width=60)
            self.aaa_input14.grid(row=16, column=1, sticky=W)
            button14 = Button(self.aaa_frame1, text="14. ?", width=3, command=clickAbout14)
            button14.grid(row=16, column=2)

            self.aaa_label15 = Label(self.aaa_frame1, text="15. Port Number:")
            self.aaa_label15.grid(row=17, column=0, sticky=W)
            self.aaa_input15 = StringVar(self.aaa_frame1)
            self.aaa_input15 = Entry(self.aaa_frame1, textvariable=self.aaa_input15, width=60)
            self.aaa_input15.grid(row=17, column=1, sticky=W)
            button15 = Button(self.aaa_frame1, text="15. ?", width=3, command=clickAbout15)
            button15.grid(row=17, column=2)

            self.aaa_label16 = Label(self.aaa_frame1, text="16. Port List:")
            self.aaa_label16.grid(row=18, column=0, sticky=W)
            self.aaa_input16 = StringVar(self.aaa_frame1)
            self.aaa_input16 = Entry(self.aaa_frame1, textvariable=self.aaa_input16, width=60)
            self.aaa_input16.grid(row=18, column=1, sticky=W)
            button16 = Button(self.aaa_frame1, text="16. ?", width=3, command=clickAbout16)
            button16.grid(row=18, column=2)

            ###------------------
            self.aaa_button2 = Button(self.aaa_frame1, text="Generate Summary", command=self.save_ts)
            self.aaa_button2.grid(row=20, column=1, columnspan=2, sticky=W)


            ###I am not too sure how to read the data to display in box
            summary_box1=Listbox(self.aaa_frame1, height=12,width=50, bg='gray')
            summary_box1.grid(row=21,column=0,rowspan=12,columnspan=2, sticky=W)
            #MY TESTS
            #path = 'my-summary'
            #path_file1 = open(path, 'r')
            #path_file2 = path_file1.read()
            #print(path_file2)
            #path_file1.close()

        def save_ts(self):
            aaaSummary1 = self.aaa_status_option1.get()
            aaaSummary2 = self.aaa_status_option2.get()
            aaaSummary3 = self.aaa_status_option3.get()
            aaaSummary4 = self.aaa_status_option4.get()
            aaaSummary5 = self.aaa_status_option5.get()
            aaaSummary6 = self.aaa_status_option6.get()
            aaaSummary7 = self.aaa_status_option7.get()
            aaaSummary8 = self.aaa_input8.get()
            aaaSummary9 = self.aaa_input9.get()
            aaaSummary10 = self.aaa_input10.get()
            aaaSummary11 = self.aaa_input11.get()
            aaaSummary12 = self.aaa_input12.get()
            aaaSummary13 = self.aaa_input13.get()
            aaaSummary14 = self.aaa_input14.get()
            aaaSummary15 = self.aaa_input15.get()
            aaaSummary16 = self.aaa_input16.get()
            with open("my-summary", "w") as file:
                file.write("{}\n".format(aaaSummary1))
                file.write("{}\n".format(aaaSummary2))
                file.write("{}\n".format(aaaSummary3))
                file.write("{}\n".format(aaaSummary4))
                file.write("{}\n".format(aaaSummary5))
                file.write("{}\n".format(aaaSummary6))
                file.write("{}\n".format(aaaSummary7))
                file.write("{}\n".format(aaaSummary8))
                file.write("{}\n".format(aaaSummary9))
                file.write("{}\n".format(aaaSummary10))
                file.write("{}\n".format(aaaSummary11))
                file.write("{}\n".format(aaaSummary12))
                file.write("{}\n".format(aaaSummary13))
                file.write("{}\n".format(aaaSummary14))
                file.write("{}\n".format(aaaSummary15))
                file.write("{}\n".format(aaaSummary16))

    frame = Tk()
    a_compute_class = ComputeAaa(frame)
    frame.title("My Build-Out")
    ######  END OF CODE  #####################

        frame.mainloop()

1 个答案:

答案 0 :(得分:0)

我可以通过太多的代码进行排序,所以这里有一个通用程序,它显示了如何使用textvariable来显示条目更改时在标签中输入的内容。

import tkinter

top = tkinter.Tk()

tk_name=tkinter.StringVar()
tk_name.set("nothing")

tkinter.Label(top, textvariable=tk_name).grid(row=0, column=1)

entry_1 = tkinter.Entry(top, textvariable=tk_name)
entry_1.grid(row=1, column=1, sticky="W")
entry_1.focus_set()

top.mainloop()