Our Tkinter application has a big ScrolledText widget which is
a log of everything that happens. In order to prevent people
from making changes, we have it in DISABLED mode except when
the program wants to write a new entry. This works OK, except
that sometimes we want to copy out of piece of the contents and
paste it in another window. When it's DISABLED, it appears
that we can't even select a portion of the text.
Is this an either-or situation? Or is there some clever way to
get around it?
If it matters, we want this to work on both Linux and Windows.
--
* Patrick L. Nolan *
* W. W. Hansen Experimental Physics Laboratory (HEPL) *
* Stanford University * 4 5334
Patrick L. Nolan wrote: Our Tkinter application has a big ScrolledText widget which is a log of everything that happens. In order to prevent people from making changes, we have it in DISABLED mode except when the program wants to write a new entry. This works OK, except that sometimes we want to copy out of piece of the contents and paste it in another window. When it's DISABLED, it appears that we can't even select a portion of the text.
Is this an either-or situation? Or is there some clever way to get around it?
If it matters, we want this to work on both Linux and Windows.
I don't know if this will help, but maybe it will provide a hint...
In a native Windows app, the way you do this is to make the edit control
read-only instead of disabled. For example, if you right-click a file in
Windows and select Properties, you'll notice that you can select and copy
text from any of the text fields in the General tab of the property sheet.
The way this is done is by making those text fields Edit controls with the
ES_READONLY style (and without the WS_DISABLED style).
-Mike
"Patrick L. Nolan" <pl*@cosmic.sta nford.edu> wrote in message news:<c4******* ***@news.Stanfo rd.EDU>... Our Tkinter application has a big ScrolledText widget which is a log of everything that happens. In order to prevent people from making changes, we have it in DISABLED mode except when the program wants to write a new entry. This works OK, except that sometimes we want to copy out of piece of the contents and paste it in another window. When it's DISABLED, it appears that we can't even select a portion of the text.
Is this an either-or situation? Or is there some clever way to get around it?
If it matters, we want this to work on both Linux and Windows.
The question is if you really need a Tkinter.Text-widget or if a
Tkinter.Listbox would satisfy your wishes. Then you could program
a scrollable Listbox as the following example:
# Vertical scrollbar for listbox
vscroll=Tkinter .Scrollbar(self ,orient='vertic al')
vscroll.grid(ro w=3,rowspan=10, column=11,stick y='ns')
# horizontal scrollbar for listbox
hscroll=Tkinter .Scrollbar(self ,orient='horizo ntal')
hscroll.grid(ro w=13,column=2,c olumnspan=9,sti cky='ew')
# Listbox
self.msgBox=Tki nter.Listbox(se lf,
bg='white',
relief='sunken' ,
xscrollcommand= hscroll.set,
yscrollcommand= vscroll.set,
)
self.msgBox.gri d(row=3,rowspan =10,column=2,co lumnspan=9,stic ky='nesw')
hscroll.configu re(command=self .msgBox.xview)
vscroll.configu re(command=self .msgBox.yview)
Then bind to all widgets to the event-function for Cntrl-C:
self.bind_all(' <Control-KeyPress-c>',self.Copy)
Where the Copy-function could look as follows:
#-----------------------------------
def Copy (self, *event):
#-----------------------------------
"""
Copies selected lines in the Listbox to Cilpboard
@para event: Dummy-parameter
@type event: list
@return: None
@rtype: NN
"""
if self.msgBox.siz e():
cs=self.msgBox. curselection()
if cs:
# Overwirte the clipboardconten t
self.msgBox.cli pboard_clear()
for lineno in cs:
self.msgBox.cli pboard_append(s elf.msgBox.get( lineno)+'\n')
I use the above example in the same app under W2kprof and HP-UX and
it works fine.
Regards
Peter
Michael Geary wrote: I don't know if this will help, but maybe it will provide a hint...
In a native Windows app, the way you do this is to make the edit control read-only instead of disabled. For example, if you right-click a file in Windows and select Properties, you'll notice that you can select and copy text from any of the text fields in the General tab of the property sheet.
The way this is done is by making those text fields Edit controls with the ES_READONLY style (and without the WS_DISABLED style).
Tk's Text widget is a custom widget, which doesn't rely on Windows native
widgets.
however, in recent versions, many Tk entry widgets supports both
state="disabled "
and state="readonly ", but I don't think this is yet available for the Text
widget.
as for the original poster, the best way to solve this is probably to add
custom
mouse bindings for this widget. here's a start (needs a bit of tweaking,
but you
get the idea):
w.tag_config("m ysel", background="blu e", foreground="whi te")
def start(event):
index = w.index("@%d,%d " % (event.x, event.y))
w.mark_set("mya nchor", index)
def drag(event):
index = w.index("@%d,%d " % (event.x, event.y))
w.tag_remove("m ysel", 1.0, END)
w.tag_add("myse l", "myanchor", index)
def copy(event):
text = w.get("mysel.fi rst", "mysel.last ")
if text: add to clipboard
w.bind("<Button-1>", start)
w.bind("<B1-Motion>", drag)
w.bind("<Contro l-C>", copy)
</F>
In article <ma************ *************** ***********@pyt hon.org>,
"Fredrik Lundh" <fr*****@python ware.com> wrote: ... however, in recent versions, many Tk entry widgets supports both state="disable d" and state="readonly ", but I don't think this is yet available for the Text widget.
as for the original poster, the best way to solve this is probably to add custom mouse bindings for this widget. here's a start...
Glad to hear about the new state="readonly ". Looking forward to that
making it into the Text widget. Meanwhile, here's the function I use. No
gurantees, but it seems to work for me. Any bug reports would be most
welcome.
-- Russell
def makeReadOnly(tk Wdg):
"""Makes a Tk widget (typically an Entry or Text) read-only,
in the sense that the user cannot modify the text (but it can
still be set programmaticall y). The user can still select and copy
text
and key bindings for <<Copy>> and <<Select-All>> still work properly.
Inputs:
- tkWdg: a Tk widget
"""
def killEvent(evt):
return "break"
def doCopy(evt):
tkWdg.event_gen erate("<<Copy>> ")
def doSelectAll(evt ):
tkWdg.event_gen erate("<<Select-All>>")
# kill all events that can change the text,
# including all typing (even shortcuts for
# copy and select all)
tkWdg.bind("<<C ut>>", killEvent)
tkWdg.bind("<<P aste>>", killEvent)
tkWdg.bind("<<P aste-Selection>>", killEvent)
tkWdg.bind("<<C lear>>", killEvent)
tkWdg.bind("<Ke y>", killEvent)
# restore copy and select all
for evt in tkWdg.event_inf o("<<Copy>>") :
tkWdg.bind(evt, doCopy)
for evt in tkWdg.event_inf o("<<Select-All>>"):
tkWdg.bind(evt, doSelectAll) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: black |
last post by:
Howdy~
i am with Win2k and had built a window with Tkinter, it has 3 button on its topright corner as common window, but what i want is just one or tow of them. ie, is there any way i can configure the appearance of minimize, maximize and close button ?
Regards~
---------------------------------
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
|
by: Justin |
last post by:
Hello,
My problem is that I am trying to use commands to
Cut/Copy/paste text from an active textbox this is because
I am calling the commands from the MDIParent. Does anyone
know how to allow a command to Cut/Copy/paste on an
MDIChilds active text? I have been completely stumped on
this and have had no other luck on web searches. Please
advise.
|
by: XmlAdoNewbie |
last post by:
Hi All,
I would like to put a method for copy, cut and paste into my
application and this seems to be easy enough except that it's not
working the way i would like it to, I thought someone might be able to
give me a bit of insight and for that I say Thank You in advance!
this is what I have so far.
private void CutText()
{
|
by: John |
last post by:
Hi
How can I implement cut or copy or paste in code?
Thanks
Regards
|
by: Glen |
last post by:
Is it possible to to detect a Tkinter top-level window being closed with the
close icon/button (top right), for example to call a function before the
window actually closes?
Python 2.4 / Linux (2.6 kernel) if that makes any difference.
Any info would be greatly appreciated.
Thanks
Glen
| |
by: Sasho Popovski |
last post by:
Is there elegant way to create Edit menu in MainMenu with standard
Copy/Cut/Paste MenuItems which will work on the Application level.
There ara Copy/Cut/Paste methods connected to the TextBox-es, but i need a
general functionality in MDI Oriented Application.
If there is a way to get the currently focused Control (TextBox), it will
do!
|
by: Bob Greschke |
last post by:
I have a program with many "forms" (Toplevel windows with entry fields).
Sometimes when I .deiconify() and .lift() a form that is a child of another
form, but that just got buried under other forms it comes up 'not active'
(dimmed). I have to click on the title bar (or anywhere in the window)
before I can start entering stuff into the entry fields. It doesn't seem to
happen all of the time, which I don't understand. Doing a .focus_set()...
|
by: roopashree |
last post by:
hi,
currently I am able to cut,copy and paste images for only one image.
Suppose I have 4 images-then I should group all the images so that I can cut/copy all 4 images and paste them. How can I do this?
I have used an array to store all the images.
If you have any code for this please send it to me or a website link.
Else logic as to how am I to Proceed.
|
by: questionit |
last post by:
If you have many controls on a Tab Control and all of them have code written for them.
Now if you want to move these controls from Tab Control to some other part of the form then the code for them will be dis-associated from them.
If you want to associate the code again with the control, it has be done manually by clicking on control's event and it will be done.
but this way, each control has to be done one by one... is there any one...
|
by: CSharpner |
last post by:
Short Question:
How do I support Cut/Paste to/from a .NET app and Windows Explorer?
Full Text:
I'm nearing the completion of a Remote File Management application.
It looks and feels a lot like Windows Explorer. The difference is
that it communicates with a remote server via web services. The
remote web services store and retrieve the file bits to/from a
database... along with some other bells and whistles that Explorer
doesn't have.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |