hi i have i open a url using urllib.request. urlopen then store the source code by using url.read to a variable and i paste the source code into the tkinter text widget but how do you keep the same format ?? -
-
with urllib.request.urlopen(path) as url:
-
sourcecode = url.read()
-
global storecode
-
storecode = sourcecode
-
tkinter.messagebox.showinfo("sourcode copied:", path)
-
Text.insert(tkinter.END,storecode)
-
#i want the source code to be kept in he same format
-
5 2127 dwblas 626
Recognized Expert Contributor
One way is to use readlines() and insert each line individually if newlines are not displaying properly. But we do not know what is wrong with the display you get, and we do not know what type of widget "Text" is. I would suggest that you take a look at the Pmw extension, especially the ScrolledText widget.
im using the standard tkinter.Text widget
i sorted it out with readlines() but im guessing the text widget is not wide enough and i need to add a horizontal scroll bar
is the scrolledtext widget better ?
thanks i have the scroll bars on, but the size of the scroll bar is really small its not the same size as the tkinter text widget, i tried putting the scroll bar in a separate frame but that did not work, how do you set the length of the scroll bar is thee an option for it?
bvdet 2,851
Recognized Expert Moderator Specialist
HTML was designed for data display with a focus on how it looks. It won't display the same in a Tkinter Text widget. Here's an example of a Tkinter Text widget with scrollbars that displays the contents of a text file: - 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)
-
self.mainFrame.grid()
-
self.exit = Tkinter.Button(self.mainFrame,
-
text="Save and Exit",
-
command=self.finish)
-
self.exit.grid(row=0, column=0, sticky="ns")
-
-
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()
-
self.quit()
-
-
if __name__ == "__main__":
-
fn = "edit.txt"
-
fnout = "editresult.txt"
-
app = App(fn, fnout)
-
app.mainloop()
-
app.destroy()
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Newgene |
last post by:
Hi, group,
I have python2.3 installed on win2k. I noticed that when I open a
dos format text file (eol is '\r\n'), readline() always returns a line
ending with '\n' only, not '\r\n'. While I read the same file on unix,
it returns a line ending with '\r\n' correctly.
This makes me difficult to determine the format of a text file, dos or
unix.
Is this a bug or intended behavior? If not a bug, then how to
determine the format of a text...
|
by: ezelasky |
last post by:
We are using the bcp utility (via APIs) to export data from a SQL table
in a fixed format text file. BCP is inserting spaces for a field if
the field contains a NULL. This is fine with us except at the end of
the line, there are no spaces for that field just the end-of-row
terminator prematurely, so it looks like that field is not present and
messes up another piece of software we pump the text file into down
stream.
Example -- The...
|
by: Jimmy |
last post by:
How can i format text, so that user input such as,
01062004 would be formatted as 01/06/2004. I've tried
several user-defined number and date formats, but I seem
to be missing something.
Thank you.
|
by: dennist685 |
last post by:
Format text as a heading
I'm progressing through a walkthrough on DetailsView control
Early on it says
Type Edit Employees, select the text, and then format the text as a heading.
I clicked format, then styles, but nowhere found how to make selected text a
heading.
|
by: a |
last post by:
keep a list of read and unread items
hi guys
i m building an rss reader and i want you suggestions for datastructure
for keeping read and unread list for each use
i m assuming it will be very sparse
thanks
| |
by: frank |
last post by:
please help!
How to keep the format of the content of a MultiLine TextBox. For example,
'new line'
I try the code:
------------------------------
TextBox.Text = "TERANET / MPAC - KEY TERMS OF USE \n" & _
"3.1 \n" & _
.......
|
by: Neil Cerutti |
last post by:
Many of the file formats I have to work with are so-called
fixed-format records, where every line in the file is a record,
and every field in a record takes up a specific amount of space.
For example, one of my older Python programs contains the
following to create a fixed-format text record for a batch of new
students:
new = file("new.dat", "w")
if not new:
|
by: gobblegob |
last post by:
Hi guys,
This is a very hard question to word. Basically i am opening a .txt file
into a label, but sometimes the .txt files are too long and you need to
scroll down. So when i open the txt file into a textbox it is not in the same format as a label , the label seem's to seperate lines and you can read it easier.
any idea's on how to read as the same format as a label
Sorry if i havnt explained properly.
GobbleGob.
|
by: metanarcissus |
last post by:
hi
i am looking for different values (quantity) in the same column in two tables with same format (same column headings).
One is the old version of our db and the other one is the new version.
These were originally excel files that i downloaded into Access as two tables and looked for unmatched records in them.
so 2 tables are exactly the same format but there has been some changes in the new table mainly quantity of the orders.
i...
|
by: kkshansid |
last post by:
what is the best way to display a word file on a php page in the same format
as it is on word format ?
word file has some very well diplay of data in tabular format
php page has includes header,footer,left,right
i want to display it in the middle but by simply copy pasting error it doesnt display in the same format
|
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: 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: 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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |