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 2120
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
Expert Mod 2GB
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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. ...
|
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...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |