Мне удалось получить ваш код для отображения текста в текстовом поле при нажатии кнопки:
![Image of user's program](https://i.stack.imgur.com/irbcE.png)
Это то, что выпытаясь достичь?Вы не упомянули, что получаете какие-либо ошибки, но я обнаружил две проблемы с вашим кодом:
- В скрипте
Button.py
, похоже, есть некоторые проблемы с отступами. - Для
self.Text1.insert(END,"hyyyy")
в вашем методе changeText()
вместо END
вы, вероятно, захотите tk.END
(например, self.Text1.insert(tk.END, "hyyyy")
).
Вот моя слегка измененная версия вашего Button.py
код, который, кажется, работает на моем конце.Я не вносил никаких изменений в ваш Button_support.py
код.
Button.py
import sys
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 Button_support
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = tk.Tk()
top = Toplevel1 (root)
Button_support.init(root, top)
root.mainloop()
w = None
def create_Toplevel1(root, *args, **kwargs):
global w, w_win, rt
rt = root
w = tk.Toplevel (root)
top = Toplevel1 (w)
Button_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("600x450+639+258")
top.title("New Toplevel")
top.configure(background="#d9d9d9")
#this is defined method and I have called in button
def changeText():
self.Text1.insert(tk.END,"hyyyy")
self.Button1 = tk.Button(top,command=changeText)
self.Button1.place(relx=0.4, rely=0.289, height=33, width=56)
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='''Button''')
self.Text1 = tk.Text(top)
self.Text1.place(relx=0.3, rely=0.089, relheight=0.12, relwidth=0.29)
self.Text1.configure(background="white")
self.Text1.configure(font="TkTextFont")
self.Text1.configure(foreground="black")
self.Text1.configure(highlightbackground="#d9d9d9")
self.Text1.configure(highlightcolor="black")
self.Text1.configure(insertbackground="black")
self.Text1.configure(selectbackground="#c4c4c4")
self.Text1.configure(selectforeground="black")
self.Text1.configure(width=174)
self.Text1.configure(wrap='word')
if __name__ == '__main__':
vp_start_gui()
Если это не то, что вам нужно, уточните, пожалуйста, какое поведениевы ожидаете, и я постараюсь изменить свой ответ соответственно.