473,378 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

whats the problem with my scrollbar ?

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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. app = Tk()
  3. app.title(" text editor")
  4.  
  5. content = ttk.Frame(app, padding=(3,3,12,12))
  6. content.grid(column=0, row=0,sticky=(N, S, E, W))
  7.  
  8. #creat label
  9. labeltext = StringVar()
  10. labeltext.set("enter url:")
  11. label1 = ttk.Label(content, textvariable=labeltext).grid(column=0, row=1, columnspan=1, rowspan=1, sticky=(N, W), padx=5)
  12.  
  13. #create text box
  14. urlname = StringVar()# text being enterd in tht text box is stored in urlname
  15.  
  16. urlname_entry = ttk.Entry(content, textvariable=urlname)
  17. urlname_entry.grid(column=1, row=1, columnspan=3,rowspan=5, sticky=(N) )
  18. #focus in the text box so user dont have to click on
  19. urlname_entry.focus()
  20. #create button
  21.  
  22. button1 = ttk.Button(content,text="get source", command=geturl)
  23. button2 = ttk.Button(content,text="count white spaces", command=count_white_space)
  24. button1.grid(column=3,row=0, columnspan=1, rowspan=2, sticky=(N,W))
  25. button2.grid(column=4,row=0,columnspan=2, rowspan=2, sticky=(N,W))
  26.  
  27.  
  28. scroll = tkinter.Scrollbar(content,borderwidth=2)
  29. Text = tkinter.Text(content,wrap=CHAR, width=50, height=20)
  30.  
  31. scroll.config(command=Text.yview)
  32. Text.config(yscrollcommand=scroll.set)
  33.  
  34. Text.grid(row=2, column=1,columnspan=1, rowspan=3, sticky=(N))
  35. scroll.grid(row=2,column=3)
  36.  
  37. app.columnconfigure(0, weight=1)
  38. app.rowconfigure(0, weight=1)
  39. content.columnconfigure(0, weight=3)
  40. content.columnconfigure(1, weight=3)
  41. content.columnconfigure(2, weight=3)
  42. content.columnconfigure(3, weight=1)
  43. content.columnconfigure(4, weight=1)
  44. content.rowconfigure(1, weight=1)
  45.  
  46.  
  47.  
  48. #adds spacing between widgets
  49. for child in app.winfo_children(): child.grid_configure(padx=5, pady=5)
  50. for child in content.winfo_children(): child.grid_configure(padx=5, pady=5)
  51.  
  52. app.bind('<Return>',geturl) #enter can also be hit
  53.  
  54.  
  55.  
  56. app.mainloop()
  57.  
  58.  
  59.  
  60.  
Feb 14 '12 #1

✓ answered by bvdet

Try this:
Expand|Select|Wrap|Line Numbers
  1. Text.config(yscrollcommand=scroll.set, wrap=tkinter.NONE,)
  2.  
  3. Text.grid(row=2, column=1,columnspan=1, rowspan=3, sticky=(N))
  4. scroll.grid(row=2,column=2, sticky='ns', rowspan=3)
  5. scrollh.grid(row=6, rowspan=1, column=1, sticky='ew')

11 8851
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.
Feb 14 '12 #2
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
Feb 14 '12 #3
and im using python 3, do you want to see my full sourcecode
Feb 14 '12 #4
bvdet
2,851 Expert Mod 2GB
You don't have to use classes. Have you tried some of my suggestions?
Feb 14 '12 #5
do you think its best to switch to a previous version of python as non of the examples in http://infohost.nmt.edu/tcc/help/pubs/tkinter.pdf work in python 3
Feb 14 '12 #6
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
Feb 14 '12 #7
bvdet
2,851 Expert Mod 2GB
Post your code and I will take a look.
Feb 14 '12 #8
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/env python
  2. from tkinter import *
  3. from tkinter import ttk
  4. import tkinter.messagebox
  5. import os
  6. import urllib.request
  7.  
  8. sourcecode = ""
  9.  
  10. def geturl(*args): #accept an argument for return
  11.     path = urlname.get()
  12.     if path == "":
  13.            tkinter.messagebox.showinfo("error", "please enter a url")
  14.     if "http://" not in path:
  15.         http ="http://"
  16.         path = http + path
  17.     with urllib.request.urlopen(path) as url:
  18.         sourcecode = url.read()
  19.         global storecode
  20.         storecode = sourcecode
  21.         string2 = "source code copied from : " + path
  22.         tkinter.messagebox.showinfo("copied", string2)
  23.         Text.delete(1.0, END)#delete currently in text box
  24.         Text.insert(tkinter.END,storecode)
  25.         return
  26.  
  27.             #find white spaces in source code
  28. def count_white_space():
  29.     path = urlname.get()
  30.     if path == "":
  31.            tkinter.messagebox.showinfo("error", "please enter a url")
  32.  
  33.     if "http://" not in path:
  34.         http ="http://"
  35.         path = http + path
  36.         with urllib.request.urlopen(path) as url:
  37.             sourcecode = url.readlines()
  38.             global storecode
  39.             storecode = sourcecode
  40.             whitespace = 0
  41.             for item in str(sourcecode):
  42.                 if item == ' ':
  43.                     whitespace +=1
  44.             string1 = "There are " + str(whitespace) + " white spaces in: " + path
  45.             tkinter.messagebox.showinfo("whitespace", string1)
  46.  
  47.  
  48. app = Tk()
  49. app.title(" text editor")
  50.  
  51. content = ttk.Frame(app, padding=(3,3,12,12))
  52. content.grid(column=0, row=0,sticky=(N, S, E, W))
  53.  
  54. #creat label
  55. labeltext = StringVar()
  56. labeltext.set("enter url:")
  57. label1 = ttk.Label(content, textvariable=labeltext).grid(column=0, row=1, columnspan=1, rowspan=1, sticky=(N, W), padx=5)
  58.  
  59. #create text box
  60. urlname = StringVar()# text being enterd in tht text box is stored in urlname
  61.  
  62. urlname_entry = ttk.Entry(content, textvariable=urlname)
  63. urlname_entry.grid(column=1, row=1, columnspan=3,rowspan=5, sticky=(N) )
  64. #focus in the text box so user dont have to click on
  65. urlname_entry.focus()
  66. #create button
  67.  
  68. button1 = ttk.Button(content,text="get source", command=geturl)
  69. button2 = ttk.Button(content,text="count white spaces", command=count_white_space)
  70. button1.grid(column=3,row=0, columnspan=1, rowspan=2, sticky=(N,W))
  71. button2.grid(column=4,row=0,columnspan=2, rowspan=2, sticky=(N,W))
  72.  
  73.  
  74. scroll = tkinter.Scrollbar(content,borderwidth=2)
  75. Text = tkinter.Text(content,wrap=CHAR, width=30, height=20)
  76. scrollh = tkinter.Scrollbar(content,borderwidth=2, orient=HORIZONTAL)
  77.  
  78.  
  79. scrollh.config(command=Text.xview)
  80. Text.config(xscrollcommand=scrollh.set)
  81.  
  82. scroll.config(command=Text.yview)
  83. Text.config(yscrollcommand=scroll.set)
  84.  
  85. Text.grid(row=2, column=1,columnspan=1, rowspan=3, sticky=(N))
  86. scroll.grid(row=3,column=3)
  87. scrollh.grid(row=6, rowspan=3, column=1)
  88.  
  89. app.columnconfigure(0, weight=1)
  90. app.rowconfigure(0, weight=1)
  91. content.columnconfigure(0, weight=3)
  92. content.columnconfigure(1, weight=3)
  93. content.columnconfigure(2, weight=3)
  94. content.columnconfigure(3, weight=1)
  95. content.columnconfigure(4, weight=1)
  96. content.rowconfigure(1, weight=1)
  97.  
  98.  
  99.  
  100.  
  101. #text = Text(app, width=80,height=40, wrap='none').grid(row=2, column=2)
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. #adds spacing between widgets
  109. for child in app.winfo_children(): child.grid_configure(padx=5, pady=5)
  110. for child in content.winfo_children(): child.grid_configure(padx=5, pady=5)
  111.  
  112. app.bind('<Return>',geturl) #enter can also be hit
  113.  
  114.  
  115.  
  116. app.mainloop()
  117.  
Feb 14 '12 #9
bvdet
2,851 Expert Mod 2GB
Try this:
Expand|Select|Wrap|Line Numbers
  1. Text.config(yscrollcommand=scroll.set, wrap=tkinter.NONE,)
  2.  
  3. Text.grid(row=2, column=1,columnspan=1, rowspan=3, sticky=(N))
  4. scroll.grid(row=2,column=2, sticky='ns', rowspan=3)
  5. scrollh.grid(row=6, rowspan=1, column=1, sticky='ew')
Feb 14 '12 #10
it work i really appreciate your help, can you explain where i went wrong, so the scroll.grid have to include sticky and rowspan
Feb 14 '12 #11
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
Feb 15 '12 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
0
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...
3
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,...
6
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...
1
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....
0
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 =...
1
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...
2
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....
2
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>
1
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...
0
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...
0
isladogs
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.