Я много искал, пытаясь найти ответ на этот вопрос. Я новичок в этом, поэтому, пожалуйста, потерпите меня, я делаю это как можно проще.
У меня есть два python скрипта. GUI скрипт с кнопкой и записью, а также скрипт с функциями, которые отображают сообщение в записи при нажатии кнопки. Я смог получить кнопку в скрипте GUI для вызова функции в другом скрипте, импортировав ее и используя функцию лямбда, и заставил ее просто напечатать тестовое сообщение. Теперь мне нужно, чтобы эта функция изменила значение в записи, которая находится в скрипте GUI.
GUI script:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 5.0.3
# in conjunction with Tcl version 8.6
# Apr 01, 2020 12:37:32 PM PDT platform: Windows NT
import sys
import Test_1_Functions
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
try:
import ttk
py3 = False
except ImportError:
import tkinter.ttk as ttk
py3 = True
import Test_1_GUI_support
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = tk.Tk()
top = Toplevel1 (root)
Test_1_GUI_support.init(root, top)
root.mainloop()
w = None
def create_Toplevel1(rt, *args, **kwargs):
'''Starting point when module is imported by another module.
Correct form of call: 'create_Toplevel1(root, *args, **kwargs)' .'''
global w, w_win, root
#rt = root
root = rt
w = tk.Toplevel (root)
top = Toplevel1 (w)
Test_1_GUI_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_Toplevel1():
global w
w.destroy()
w = None
class Toplevel1:
def __init__(self, top=None):
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
_bgcolor = '#d9d9d9' # X11 color: 'gray85'
_fgcolor = '#000000' # X11 color: 'black'
_compcolor = '#d9d9d9' # X11 color: 'gray85'
_ana1color = '#d9d9d9' # X11 color: 'gray85'
_ana2color = '#ececec' # Closest X11 color: 'gray92'
top.geometry("1350x900+301+103")
top.minsize(120, 1)
top.maxsize(4924, 1901)
top.resizable(1, 1)
top.title("New Toplevel")
top.configure(background="#d9d9d9")
self.Button1 = tk.Button(top)
self.Button1.place(relx=0.37, rely=0.344, height=94, width=197)
self.Button1.configure(activebackground="#ececec")
self.Button1.configure(activeforeground="#000000")
self.Button1.configure(background="#d9d9d9")
self.Button1.configure(disabledforeground="#a3a3a3")
self.Button1.configure(foreground="#000000")
self.Button1.configure(highlightbackground="#d9d9d9")
self.Button1.configure(highlightcolor="black")
self.Button1.configure(pady="0")
self.Button1.configure(text='''Press Me''')
self.Button1.configure(command = lambda: Test_1_Functions.func())
self.Entry1 = tk.Entry(top)
self.Entry1.place(relx=0.356, rely=0.256,height=60, relwidth=0.173)
self.Entry1.configure(background="white")
self.Entry1.configure(disabledforeground="#a3a3a3")
self.Entry1.configure(font="TkFixedFont")
self.Entry1.configure(foreground="#000000")
self.Entry1.configure(insertbackground="black")
И скрипт функции:
from Test_1_GUI import Toplevel1
def func():
#print 'pressed'
Toplevel1.Entry1.insert(0, 'MSG')
Я получаю ошибку:
Exception in Tkinter callback
Traceback (most recent call last):
File "D:\Python27\lib\lib-tk\Tkinter.py", line 1547, in __call__
return self.func(*args)
File "D:\DS Cloud\Python\Page-Tkinter\Test_1_OOP\Test_1_GUI.py", line 78, in <lambda>
self.Button1.configure(command = lambda: Test_1_Functions.func())
File "D:\DS Cloud\Python\Page-Tkinter\Test_1_OOP\Test_1_Functions.py", line 6, in func
val = Toplevel1.editEntry()
TypeError: unbound method editEntry() must be called with Toplevel1 instance as first argument (got nothing instead)
Я ценю всю помощь
Джамиль