【问题标题】:tkinter/python How i can transfer text from one frame to other using tkinter using python [closed]tkinter/python 如何使用 python 使用 tkinter 将文本从一帧传输到另一帧 [关闭]
【发布时间】:2019-01-18 13:15:48
【问题描述】:

我无法通过单击按钮将相同的数据从一帧发送到另一帧 tkinter/python 如何使用 tkinter 将文本从一帧传输到另一帧

from tkinter import *

root = Tk()

frame = Frame(root, width=1000, height=1000)
frame.pack()

tbox1 = Text(frame)
tbox1.place(x=0, y=0, height=400, width=600)

tbox2 = Text(frame)
tbox2.place(x=0, y=400, height=1000, width=1000)


tbox3 = Text(frame)
tbox3.place(x=500, y=0, height=400, width=500)
button1 = Button(frame, text='Check', width="20", height="3", font='helvetica 20', bg="green",
                            command=lambda: set(tbox1))
button1.place(x=700, y=700, height=30, width=100)

root.mainloop()

【问题讨论】:

    标签: python tkinter frames


    【解决方案1】:

    set() 不能这样工作。您只能将 set() 与特定的小部件或 tkinter 变量一起使用,例如 StringVar()

    您可以使用get()insert() 在文本字段之间移动数据。

    在您的按钮上方添加此功能。

    def copy_data():
        tbox2.delete(1.0, 'end')
        tbox2.insert(1.0, tbox1.get(1.0, 'end-1c'))
    

    并将您的按钮更改为:

    Button(frame, text='Check', width="20", height="3", font='helvetica 20', bg="green",
           command=copy_data).place(x=700, y=700, height=30, width=100)
    

    【讨论】:

    • 谢谢您,它工作正常
    • 先生,如果我想从后端获取文件并使用关键字将该文件导入 tbox1 框架,我该如何使用它
    猜你喜欢
    • 2015-10-02
    • 2018-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多