my scroll bar works but the size is to small and how would i go by adding a horizontal scroll bar ? help would be appreciated thanks. -
-
app = Tk()
-
app.title(" text editor")
-
-
content = ttk.Frame(app, padding=(3,3,12,12))
-
content.grid(column=0, row=0,sticky=(N, S, E, W))
-
-
#creat label
-
labeltext = StringVar()
-
labeltext.set("enter url:")
-
label1 = ttk.Label(content, textvariable=labeltext).grid(column=0, row=1, columnspan=1, rowspan=1, sticky=(N, W), padx=5)
-
-
#create text box
-
urlname = StringVar()# text being enterd in tht text box is stored in urlname
-
-
urlname_entry = ttk.Entry(content, textvariable=urlname)
-
urlname_entry.grid(column=1, row=1, columnspan=3,rowspan=5, sticky=(N) )
-
#focus in the text box so user dont have to click on
-
urlname_entry.focus()
-
#create button
-
-
button1 = ttk.Button(content,text="get source", command=geturl)
-
button2 = ttk.Button(content,text="count white spaces", command=count_white_space)
-
button1.grid(column=3,row=0, columnspan=1, rowspan=2, sticky=(N,W))
-
button2.grid(column=4,row=0,columnspan=2, rowspan=2, sticky=(N,W))
-
-
-
scroll = tkinter.Scrollbar(content,borderwidth=2)
-
Text = tkinter.Text(content,wrap=CHAR, width=50, height=20)
-
-
scroll.config(command=Text.yview)
-
Text.config(yscrollcommand=scroll.set)
-
-
Text.grid(row=2, column=1,columnspan=1, rowspan=3, sticky=(N))
-
scroll.grid(row=2,column=3)
-
-
app.columnconfigure(0, weight=1)
-
app.rowconfigure(0, weight=1)
-
content.columnconfigure(0, weight=3)
-
content.columnconfigure(1, weight=3)
-
content.columnconfigure(2, weight=3)
-
content.columnconfigure(3, weight=1)
-
content.columnconfigure(4, weight=1)
-
content.rowconfigure(1, weight=1)
-
-
-
-
#adds spacing between widgets
-
for child in app.winfo_children(): child.grid_configure(padx=5, pady=5)
-
for child in content.winfo_children(): child.grid_configure(padx=5, pady=5)
-
-
app.bind('<Return>',geturl) #enter can also be hit
-
-
-
-
app.mainloop()
-
-
-
-
Try this: - Text.config(yscrollcommand=scroll.set, wrap=tkinter.NONE,)
-
-
Text.grid(row=2, column=1,columnspan=1, rowspan=3, sticky=(N))
-
scroll.grid(row=2,column=2, sticky='ns', rowspan=3)
-
scrollh.grid(row=6, rowspan=1, column=1, sticky='ew')
11 8866 bvdet 2,851
Expert Mod 2GB
Scrollbar.grid needs to be configured sticky='ns' and rowspan=3. A horizontal scrollbar will be added the same way but configured orient=Tkinter.HORIZONTAL and w.grid sticky="ew". Configure the Text widget xscrollcommand=hscrollbar.set and hscrollbar["command"] = self.textWidget.xview.
I posted an example Text widget with horizontal and vertical scrollbars in this thread.
so do i need to re write my whole code so it can include classes and self, i haven't used classes before in python
and im using python 3, do you want to see my full sourcecode
bvdet 2,851
Expert Mod 2GB
You don't have to use classes. Have you tried some of my suggestions?
yes i have i have added a horizontal scroll bar but its not working with the text widget only the vertical scroll bar is working
bvdet 2,851
Expert Mod 2GB
Post your code and I will take a look.
-
#!/usr/bin/env python
-
from tkinter import *
-
from tkinter import ttk
-
import tkinter.messagebox
-
import os
-
import urllib.request
-
-
sourcecode = ""
-
-
def geturl(*args): #accept an argument for return
-
path = urlname.get()
-
if path == "":
-
tkinter.messagebox.showinfo("error", "please enter a url")
-
if "http://" not in path:
-
http ="http://"
-
path = http + path
-
with urllib.request.urlopen(path) as url:
-
sourcecode = url.read()
-
global storecode
-
storecode = sourcecode
-
string2 = "source code copied from : " + path
-
tkinter.messagebox.showinfo("copied", string2)
-
Text.delete(1.0, END)#delete currently in text box
-
Text.insert(tkinter.END,storecode)
-
return
-
-
#find white spaces in source code
-
def count_white_space():
-
path = urlname.get()
-
if path == "":
-
tkinter.messagebox.showinfo("error", "please enter a url")
-
-
if "http://" not in path:
-
http ="http://"
-
path = http + path
-
with urllib.request.urlopen(path) as url:
-
sourcecode = url.readlines()
-
global storecode
-
storecode = sourcecode
-
whitespace = 0
-
for item in str(sourcecode):
-
if item == ' ':
-
whitespace +=1
-
string1 = "There are " + str(whitespace) + " white spaces in: " + path
-
tkinter.messagebox.showinfo("whitespace", string1)
-
-
-
app = Tk()
-
app.title(" text editor")
-
-
content = ttk.Frame(app, padding=(3,3,12,12))
-
content.grid(column=0, row=0,sticky=(N, S, E, W))
-
-
#creat label
-
labeltext = StringVar()
-
labeltext.set("enter url:")
-
label1 = ttk.Label(content, textvariable=labeltext).grid(column=0, row=1, columnspan=1, rowspan=1, sticky=(N, W), padx=5)
-
-
#create text box
-
urlname = StringVar()# text being enterd in tht text box is stored in urlname
-
-
urlname_entry = ttk.Entry(content, textvariable=urlname)
-
urlname_entry.grid(column=1, row=1, columnspan=3,rowspan=5, sticky=(N) )
-
#focus in the text box so user dont have to click on
-
urlname_entry.focus()
-
#create button
-
-
button1 = ttk.Button(content,text="get source", command=geturl)
-
button2 = ttk.Button(content,text="count white spaces", command=count_white_space)
-
button1.grid(column=3,row=0, columnspan=1, rowspan=2, sticky=(N,W))
-
button2.grid(column=4,row=0,columnspan=2, rowspan=2, sticky=(N,W))
-
-
-
scroll = tkinter.Scrollbar(content,borderwidth=2)
-
Text = tkinter.Text(content,wrap=CHAR, width=30, height=20)
-
scrollh = tkinter.Scrollbar(content,borderwidth=2, orient=HORIZONTAL)
-
-
-
scrollh.config(command=Text.xview)
-
Text.config(xscrollcommand=scrollh.set)
-
-
scroll.config(command=Text.yview)
-
Text.config(yscrollcommand=scroll.set)
-
-
Text.grid(row=2, column=1,columnspan=1, rowspan=3, sticky=(N))
-
scroll.grid(row=3,column=3)
-
scrollh.grid(row=6, rowspan=3, column=1)
-
-
app.columnconfigure(0, weight=1)
-
app.rowconfigure(0, weight=1)
-
content.columnconfigure(0, weight=3)
-
content.columnconfigure(1, weight=3)
-
content.columnconfigure(2, weight=3)
-
content.columnconfigure(3, weight=1)
-
content.columnconfigure(4, weight=1)
-
content.rowconfigure(1, weight=1)
-
-
-
-
-
#text = Text(app, width=80,height=40, wrap='none').grid(row=2, column=2)
-
-
-
-
-
-
-
#adds spacing between widgets
-
for child in app.winfo_children(): child.grid_configure(padx=5, pady=5)
-
for child in content.winfo_children(): child.grid_configure(padx=5, pady=5)
-
-
app.bind('<Return>',geturl) #enter can also be hit
-
-
-
-
app.mainloop()
-
bvdet 2,851
Expert Mod 2GB
Try this: - Text.config(yscrollcommand=scroll.set, wrap=tkinter.NONE,)
-
-
Text.grid(row=2, column=1,columnspan=1, rowspan=3, sticky=(N))
-
scroll.grid(row=2,column=2, sticky='ns', rowspan=3)
-
scrollh.grid(row=6, rowspan=1, column=1, sticky='ew')
it work i really appreciate your help, can you explain where i went wrong, so the scroll.grid have to include sticky and rowspan
bvdet 2,851
Expert Mod 2GB
The horizontal scrollbar will never work unless the text window needs to expand. It will only need to expand if wrap=tkinter.NONE Sign in to post your reply or Sign up for a free account.
Similar topics
by: aa |
last post by:
I want to lunch ASP page but I am getting this error. (The path is correct
and default page is default.asp)
The page cannot be found
The page you are looking for might have been removed, had its...
|
by: ZenMaster |
last post by:
Hello, can anyone help me figure out what may be wrong
with my code -
In VC++ 6.0 Ive created a ScrollBar using :
--------------------------------------------
hwndScrollHue = CreateWindowEx...
|
by: Vaidas Gudas |
last post by:
I has web project on virtual pc, maked with framework 2.0. there I was used
the method role.roleexists("admin") and everything was worked good.
but when i replace this project on my local machine,...
|
by: rajesh |
last post by:
Is it possible to display the select box without scrollbar
in my program there is a need for that . The code attached below
contains 2 select box and four buttons and the button is used to...
|
by: wincek |
last post by:
Hi All,
Below .css works with default.html without problem but when i use it in
default.aspx, do nothing. When i use it in separate .css file, and link it
to defaulat.aspx stiil do nothing....
|
by: Mark Smith |
last post by:
hi
i use an ownerdraw method for coloring some items in the list different
then the others.
code:
private void ListBoxDrawItem(object sender, DrawItemEventArgs e)
{
ListBox lst =...
|
by: Tom |
last post by:
First, I posted a similar request for help in another group and now
don't find the posting. Problem with my newsreader perhaps ... but
apologies if this appears as a cross posting.
My code is...
|
by: pssraju |
last post by:
Hi,
I am having applet display problem on my PC and the same thing working fine on some of my colleagues PC's. When I cross checked content through view source its exactly same on both the PC's....
|
by: madhuriks |
last post by:
hi,
im unable to clear the txt field..what is the problem..
<form>
<input type=text value="Hello"><br>
<input type="reset">
</form>
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: 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: 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...
|
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,...
| |