Hi Guys,
I'm new to Python. And I'm preparing a GUI in Python and I need to add scroll bar to the Text box. And I'm using 'Tkinter GRID' manager for this. Attached is the image of text box what I need.
I'm getting very large text box if I add a Scroll Bar into it. Below is the code what I have tried,
Please any body help me. -
TextBox1 = Entry(resultFrame)
-
datFileText.grid(row=2, column=0, padx=20, ipadx=200, ipady=40)
-
scrollBar1 = ScrolledText(TextBox1 )
-
scrollBar1.grid(sticky=E)
Thanks in advance
Manoj
2 9301 bvdet 2,851
Expert Mod 2GB
You don't show what datFileText is in the code you posted. Below is a Tkinter application with a Tkinter.Text widget and scrollbars. The ScrolledText module in Python 2.7 uses the same constructor as Tkinter.Text.
A Tkinter.Entry widget can only be scrolled horizontally. It takes some extra work to setup. The New Mexico Tech Tkinter 8.4 reference can show you how. - import Tkinter
-
"""
-
Edit a file and save the text.
-
"""
-
-
textFont1 = ("Courier New", 16, "normal")
-
-
class ScrollbarX(Tkinter.Scrollbar):
-
def set(self, low, high):
-
if float(low) <= 0.0 and float(high) >= 1.0:
-
self.grid_remove()
-
else:
-
self.grid()
-
Tkinter.Scrollbar.set(self, low, high)
-
-
class App(Tkinter.Tk):
-
def __init__(self, fn, fnout):
-
Tkinter.Tk.__init__(self)
-
self.title("Text Widget")
-
self.fin = open(fn, 'r')
-
self.fnout = fnout
-
self.mainFrame = Tkinter.Frame(self)
-
-
top=self.winfo_toplevel()
-
top.columnconfigure(0, weight=1)
-
top.rowconfigure(0, weight=1)
-
-
self.mainFrame.grid(row=0, column=0, sticky="nsew")
-
self.exit = Tkinter.Button(self.mainFrame,
-
text="Save and Exit",
-
command=self.finish)
-
self.exit.grid(row=0, column=0, sticky="ns")
-
-
-
self.mainFrame.columnconfigure(0, weight=1)
-
self.mainFrame.rowconfigure(1, weight=1)
-
-
vscrollbar = ScrollbarX(self.mainFrame)
-
vscrollbar.grid(row=1, column=1, sticky="ns")
-
hscrollbar = ScrollbarX(self.mainFrame, orient=Tkinter.HORIZONTAL)
-
hscrollbar.grid(row=2, column=0, sticky="ew")
-
-
self.textWidget = Tkinter.Text(self.mainFrame,
-
yscrollcommand=vscrollbar.set,
-
xscrollcommand=hscrollbar.set,
-
wrap=Tkinter.NONE,
-
height=24,
-
width=60,
-
font=textFont1)
-
self.textWidget.insert("1.0", self.fin.read())
-
self.textWidget.grid(row=1, column=0, sticky="nsew")
-
-
hscrollbar["command"] = self.textWidget.xview
-
vscrollbar["command"] = self.textWidget.yview
-
-
def finish(self):
-
fout = open(self.fnout, 'w')
-
fout.write(self.textWidget.get("1.0", "end"))
-
fout.close()
-
self.fin.close()
-
app.destroy()
-
-
if __name__ == "__main__":
-
fn = "edit.txt"
-
fnout = "editresult.txt"
-
app = App(fn, fnout)
-
app.mainloop()
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Andrei |
last post by:
I've installed Python 2.3b2 on Windows XP (in
"e:\programming\Python2.3"). I also have an older ActivePython 2.2.2
distro on my C-drive and Ruby which apparently installs tcl as well. Now
I'm...
|
by: vishnu mahendra |
last post by:
hello to all,
I have do create a simple editor.so Please, any one tell me how to scroll text.
happy halloween to all.
thank you in advance,
vishnu.
|
by: marijuanated |
last post by:
Hi all,
I am wondering if i could change a button text dynamically in its
handler.
for example,can we do something like this:
curButton.bind("<Button-1>",self.StopServer)
def...
|
by: nevada17 |
last post by:
My goal is to find a way to apply scroll bars across the y axis of about 25 check buttons so that my interface isn't too large. I've read about scroll bars and I realize that's its not possible to...
|
by: prashantkisanpatil |
last post by:
Hi All,
I am trying to wrap a japanese text in Python, by the following code.
if len(message) 54:
message = message.decode("UTF8")
strlist = textwrap.wrap(message,54)
After this I am...
|
by: Schwanitz |
last post by:
Hello,
how can I scroll text in a textfield using the wheel of the mouse in a form with VB?
At the moment the form is going to the next record.
Regards and thank you!
|
by: vdraceil |
last post by:
Is it possible in vb6.0 to add scroll bars to a form,so that its length and width are increased?
|
by: gobblegob |
last post by:
Well i cannont remember where i picked this code up, but i have seen
it asked for in many forums, Many times so i thought i'd add it here (Since this is my favourite forum).
Auto scroll text in...
|
by: yorlina007 |
last post by:
Hi
I need to design a tkinter widget where i should have a browse option button as you see in all windows application to select a file from my machine.
Also i need to select an integer from...
|
by: sarfarazfarru |
last post by:
sir
as am very new to the MFC just started working.
i am facing difficulties to scroll the window which has fixed text. i am not able to scroll the text both way horizontal and vertical please any...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |