Форум сайта python.su
Доброго времени суток.
Python версии 2.7.6
Текст в Entry скроллировать вправо-влево не получается, хотя, пока похожий код не был “упакован” в класс - все работало (см. второй фрагмент). Как починить?
код:
# -*- coding: utf-8 -*- from Tkinter import * class MainWindow(): def __init__(self, master=None): self.MainWindow = Tk() self.createWidgets() self.MainWindow.mainloop() def scrEnt(event, *L): if event == 'scroll': direction = L[0] discontinuity = L[1] self.ent.xview_scroll(direction, discontinuity) elif event == 'moveto': direction = L[0] self.ent.xview_moveto(direction) def createWidgets(self): self.scr = Scrollbar(self.MainWindow, orient = HORIZONTAL, command = self.scrEnt) self.ent = Entry(self.MainWindow, font='Arial 12', xscrollcommand = self.scr.set) self.ent.pack() self.scr.pack(fill = BOTH) mw = MainWindow()
# -*- coding: utf-8 -*- from Tkinter import * def scrEnt(event, *L): if event == 'scroll': direction = L[0] discontinuity = L[1] ent.xview_scroll(direction, discontinuity) elif event == 'moveto': direction = L[0] ent.xview_moveto(direction) MainWindow = Tk() scr = Scrollbar(MainWindow, orient = HORIZONTAL, command = scrEnt) ent = Entry(MainWindow, font='Arial 12', xscrollcommand = scr.set) ent.pack() scr.pack(fill = BOTH) MainWindow.mainloop()
Офлайн
а как же self?!
def scrEnt(self, event, *L):
# . . . class MainWindow(): def __init__(self, master=None): self.MainWindow = Tk() self.createWidgets() self.MainWindow.mainloop() def scrEnt(self, event, *L): if event == 'scroll': direction = L[0] discontinuity = L[1] self.ent.xview_scroll(direction, discontinuity) elif event == 'moveto': direction = L[0] self.ent.xview_moveto(direction) # . . .
from Tkinter import *
Отредактировано terabayt (Март 31, 2015 21:22:48)
Офлайн
terabayt
Офлайн
class MainWindow(): def __init__(self, master=None): self.MainWindow = Tk() self.createWidgets() self.MainWindow.mainloop()
Офлайн