0

So while 'designing' my tkinter application i noticed this white stripe appearing next to the scrollbar there:

It is not disappearing when the scrollbar gets to an active state but it is definetly part of the Scrollbar itself because there is nothing under it in my programm which has a white background. It seems to appear no matter if I use grid or pack. In this case I use grid - here the little extract of my code:

class App(Tk):
    def __init__(self):

        #other stuff

        self.hvf=hvFrame(self,sticky=EW,showfocus=S,bg='white',padx=5,pady=5)
        self.hvf.grid(row=1,column=0,columnspan=2,sticky=NSEW,pady=5,padx=(0,5))
        sb=Scrollbar(self,orient=VERTICAL,command=self.hvf.yview,bd=0,highlightthickness=0)
        sb.grid(row=1,column=2,sticky=NSEW,pady=5)
        self.hvf.config(yscrollcommand=sb.set)

If you ned more, then here you go. (Should not be executable for you because you do not have the extras file but you should still be able to understand it.)

EDIT:

A little reproduceable example:

from tkinter import Tk,Frame,Scrollbar,VERTICAL,NS
root = Tk()
frame = Frame(root,height=300,width=500)
frame.grid(row=0,column=0,padx=(0,5),pady=5)
sb = Scrollbar(root,orient=VERTICAL)
sb.grid(row=0,column=1,sticky=NS,pady=5)
root.mainloop()
Nummer_42O
  • 334
  • 2
  • 16
  • _" there is nothing under it in my programm which has a white background. "_ That is contradicted by the code where you explicitly set the background of `self.hvf` to white. If you change the background of that frame to red, does this vertical strip also turn red? – Bryan Oakley Jan 30 '20 at 17:34
  • Nope. It can't even because Scrollbar is neither placed on the hvFrame nor a subwidget of it. It is just right next to it. There is even a 5 pixel gap between them as can be seen in the hvFrames grid (```padx=(0,5)```). – Nummer_42O Jan 30 '20 at 17:44
  • It would help if you created a [mcve]. We can't run the code in the question itself, and we can't run the code you linked to. I also recommend at least trying to change the white to red to verify your assumptions. You claimed absolutely nothing in the program has a white background, but clearly something does. Perhaps some of your assumptions are false. – Bryan Oakley Jan 30 '20 at 17:49
  • Well before I answered you I actually tried. ;) But I added a little example to my question. :D – Nummer_42O Jan 30 '20 at 17:55
  • If we can't run the example, it's largely useless. Sometimes we can guess at a solution, but it's best to create a proper reproducible example. – Bryan Oakley Jan 30 '20 at 17:58
  • You answered before the EDIT was online. ^^' – Nummer_42O Jan 30 '20 at 18:00
  • The reproducible example is vastly different than your other code. For example, you're not setting the borderwidth and highlightthickness, and the grid options are different. Plus, the example _doesn't work_. It fails for trivial reasons, but we shouldn't have to fix trivial bugs just to get it to run. Since it won't run, it leaves me wondering why you think it replicates the problem you've having. – Bryan Oakley Jan 30 '20 at 18:10
  • Ok I corrected it and for me it works now. And if you run it you're gonna encounter the same stripe there unless it's a problem limited to my device. And wther or not it's a direct representation schoudn't matter then. It still produces this... I'll just call it a bug. Btw. it also appears if you just use pack... – Nummer_42O Jan 30 '20 at 18:27
  • I see the white line in you working example. I wonder if that is part of the scrollbar widget. I will have to review my other programs that have a scrollbar. I believe that the tkinter scrollbar pulls its design from your computers window manager so that white strip may results from that. If that is the case you may have to use a custom scrollbar to get rid of it. – Mike - SMT Jan 30 '20 at 18:27
  • I don't have a linux or windows box to test, but with the example on OSX I see the background of the root window in the few pixels between the scrollbar and the frame. – Bryan Oakley Jan 30 '20 at 18:31
  • I recommend changing the background of the root window to something that stands out, and changing the background of the frame to a different color that stands out, and then see if the white artifact changes color. In the example, it could also be the border or highlight color that's showing. – Bryan Oakley Jan 30 '20 at 18:36
  • @BryanOakley On windows that white line is showing up. I did change the theme on my windows to dark and the header bar changed color but not the scroll bar so I am not sure if that helps anything. One solution is to use a custom scrollbar that I use. I have one simply to be able to color my scrollbar to match my app theme but at least my custom scrollbar does not show that white line. – Mike - SMT Jan 30 '20 at 18:37
  • I'm not talking about changing the theme, I'm literally suggesting you set the background color of the root window (eg: `root.configure(bg='red')`). – Bryan Oakley Jan 30 '20 at 18:38
  • @BryanOakley ya I set both the frame and root bg to black and then overlay the new window over the old. That white line still exist. At this pint my only guess is that it is simply a result of the widget design being pulled from Window. – Mike - SMT Jan 30 '20 at 18:43

1 Answers1

1

After testing a few things like changing the windows theme or changing the root and frame background to black the while line still comes up. I cannot be 100% sure but I believe this is due to fact that tkinter on Windows pulls the scrollbar design from Windows itself and it is simply part of that design. It may be a design choice to give the scroll bar some visual depth. That said you cannot do anything to change the design of the scrollbar within a Windows environment so you as stuck with this unless you write a custom scrollbar.

Example code:

import tkinter as tk

root = tk.Tk()
root['bg'] = 'black'
frame = tk.Frame(root, height=300, width=500, background='black')
frame.grid(row=0, column=0)
sb = tk.Scrollbar(root, orient=tk.VERTICAL)
sb.grid(row=0, column=1, sticky=tk.NS)
root.mainloop()

Results from overlay of white and black backgrounds:

enter image description here

Below is the code I use for a custom scrollbar (but did not write myself). You can find the post where I got the code here.

Mike - SMT
  • 14,784
  • 4
  • 35
  • 79
  • Thanks! I feared it would be somehting like that but hoped it was just a bug that might be fixable. But I guess I'll go and write my own Scrollbar then (I could use your posted example but it's always a great exercise to do such stuff yourself. ^^). – Nummer_42O Feb 03 '20 at 11:55
  • @Nummer_42O Glad to help. – Mike - SMT Feb 03 '20 at 13:59