How to remove the annoying extra bit of a tkinter.ttk scale - python

There is this very annoying extra bit on ttk(tkinter.ttk) scale here is the image at the end there is an extra bit, which would annoy some people if they notice it(you would kinda be able to spot it). I had it print out what number the scale was and it was at the max it could be. Here is the code of the scale
width = Scale(optionsframe, from_ = 1, to = 20, style = 'SCALEBG.Horizontal.TScale')
width.grid(row = 0, column = 7)
Here is an image without using style
The style code
scalebg = ttk.Style()
scalebg.configure('SCALEBG.Horizontal.TScale', foreground = '#2a2a2a', background = '#2a2a2a')
This occurs for both styles.
Edit
From the comments it looks like it only happens when the vista and xpnative are used, which in my opinion give the best GUI look. Is there way to create your own style which would remove the extra bit and looks identical to the one tkinter provieds.

Related

PySimpleGUI need help planning an intricate measurements calculator

i'm working on a program that should figure out the dimensions of individual pieces in kitchen cabinet modules, so you only set: height, depth, width of the material(18mm), and then you select modules from a list and after setting the dimensions of each you should be presented with a list of pieces and their dimensions.
Since all of this is somewhat standardized individual pieces's dimensions are figured out by simple math, but each consists of it's own set of operations, which should be ran once and display the results in the interface(eventually i'll figure out how to write it to an excel compatible format)
as you can see here it can get to be complex, i can work it out over time no problem, but right now i'm not sure PYGUI is what i need.
import PySimpleGUI as sg
layout1 = [[sg.Text('Altura', size=(10,1)),sg.Input('',key='Alt')], #Height
[sg.Text('Densidad Placa', size=(10,1)),sg.Input('',key='Placa')],# Material's density
[sg.Text('Profundidad', size=(10,1)),sg.Input('',key='Prof')]] #Depth
layout2 = [[sg.Text('Ancho Modulo', size=(10,1)),sg.Input('',key='WM')], #Module's width
[sg.Text('lateral', size=(10,1)),sg.Text('',key='Lat'),sg.Text('x'),sg.Text('',key='Prof2')], #side pieces
[sg.Text('Piso', size=(10,1)),sg.Text('',key='WM2'),sg.Text('x'),sg.Text('',key='Prof2')], # bottom piece
[sg.Button('Go')]]
#Define Layout with Tabs
tabgrp = [[sg.TabGroup([[sg.Tab('1', layout1),
sg.Tab('2', layout2)]])]]
window =sg.Window("Tabs",tabgrp)
#Read values entered by user
while True:
event,values=window.read()
if event in (sg.WINDOW_CLOSED, 'Close'):
break
elif event == 'Go':
anc = values['WM']
altura = values['Alt']
placa = values['Placa']
prof = values['Prof']
try:
v = int(anc) #width
w = int(prof)#depth
x = int(altura)#height
y = int (placa)# Material's density
altlat = str(x - y) #height of side pieces
prof2 = int(w - y) #depth of pieces,(total depth incluiding the door)
ancm = int(v) #width
except ValueError:
altlat = "error"
prof2 = "error"
ancm = "error"
window['Lat'].update(value=altlat)
window['Prof2'].update(value=prof2)
window['WM2'].update(value=ancm)
window.refresh
#access all the values and if selected add them to a string
window.close()
i figured i use functions for every set of operations and call them as i need them, but keys can't be reused and every tutorial i've seen points towards them, and other implementations i tried failed,. i've been using python since last night, so i'm not sure how many options i have, nor how limited my options will be with PYGUI's toolset.
I think what you are asking is, how can I make a function that will take the values and run an operation on them? This seems to be more of a general python question than one about pyGUI, but here is a quick answer.
def calc_side_panel_height(altura, placa):
x = int(altura)#height
y = int (placa)# Material's density
return (x - y) #height of side pieces
try {
height_of_side = calc_side_panel_height(altura, place)
# use height here.
altlat = str(height_of_side)
}
does that start to make sense? You would call functions and in those functions do the calculations, so you don't have to rewrite the code.
more info: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Functions
Let me know if I'm confused!

Colorize parts of a complex equation manim

I want to paint variables of MathTex element in different colors, but Manim seems to have problems with comlicated Latex expressions.
Here is my scene.
from manim import *
config.frame_width = 260
class Find_Path(Scene):
def construct(self):
obj = MathTex(r"minimize \quad \sum_{start}^{end}\frac{d_{i,i+1}}{v_{i,i+1}}",
font_size=1000, substrings_to_isolate="d" and "v")
obj.set_color_by_tex("d", YELLOW)
obj.set_color_by_tex("start", GREEN)
obj.set_color_by_tex("end", GREEN)
obj.set_color_by_tex("v", RED)
self.play(Write(obj))
self.wait(3)
Here is the result.
Specifically, I want to color d_{i,i+1} in YELLOW, v_{i,i+1} in RED, start and end in GREEN.
Any advice? Frankly, I do not want to create several MathTex object in different colors and then arrange them.
Manim does a bunch of tex rewriting under the covers, and it seems that over is preferred to frac because of that rewriting.
I was able to apply the colors that you wanted (although I suspect you didn't want the sum symbol colored) with:
from manim import *
class Find_Path(Scene):
def construct(self):
obj1 = MathTex(r"\text{minimize}", r"\quad \sum_{\text{start}}^{\text{end}}")
obj2 = MathTex(r"d_{i,i+1}", r"\over", r"v_{i,i+1}")
obj1.set_color_by_tex("start", GREEN)
obj1.set_color_by_tex("end", GREEN)
obj2.move_to(obj1, RIGHT)
obj2.shift(1.5 * RIGHT)
obj2[0].set_color(YELLOW)
obj2[2].set_color(RED)
self.play(AnimationGroup(Write(obj1), Write(obj2)))
self.wait(3)
but I had to resort to separate objects. Worse still, I aligned them by hand with a fudge factor.
Late answer, but I encountered a similar issue and ended up here before finding the relevant section in the documentation.
Relevant section in documentation: Using index_labels to work with complicated strings
An example with your special case:
from manim import *
config.frame_width = 8
config.frame_size = (1300, 1000)
class FindPath(Scene):
def construct(self):
# You can split the string in parts
minimize = r"minimize \quad "
summ = r"\sum_{start}^{end}"
frac = r"\frac{d_{i,i+1}}{v_{i,i+1}}"
tex = MathTex(minimize, summ, frac).shift(2 * UP)
# Observe first level labels
tex_ = tex.copy().next_to(tex, DOWN)
self.add(index_labels(tex_, color=YELLOW))
# Observe second level labels
tex__ = tex_.copy().next_to(tex_, DOWN)
for part in tex__:
self.add(index_labels(part, color=YELLOW))
# Finally you can color accordingly
tex[1][0:3].set_fill(color=GREEN)
tex[1][4:9].set_fill(color=GREEN)
tex[2][0:6].set_fill(color=YELLOW)
tex[2][7:13].set_fill(color=RED)
self.add(tex, tex_, tex__)

Make tkinter Scale span it's full grid cell

I have a Tkinter ttk.Scale in a GUI. What I want to do is add some labels on the top or bottom (or side if its vertical) that show the values the user is selecting through. I have a minimum working example shown below.
My problem comes from the fact that I cannot figure out how to get the Scale to line up with the labels. It is set to span all the columns of the labels, but the Scale widget comes with a length keyword that automatically forces it to be 100 pixels in size. I can't know, a priori, what to set that length to and I can't figure out how to tell it to fill its grid space.
Is there a way to tell the Scale to choose a length such that it fills its grid space?
import tkinter as tk
from tkinter import ttk
def show_values():
print (w1.get())
def scaleFunc(val):
scaleVal = float(w1.get())
if int(scaleVal) != scaleVal:
w1.set(round(float(val)))
root = tk.Tk()
for i,text in enumerate(['O','B','A','F','G','K','M','L']):
ttk.Label(root, text = text).grid(row=0,column=i,padx=10)
w1 = ttk.Scale(root, to=7, command=scaleFunc, length=None)
w1.grid(row = 1, column = 0, columnspan = 8,ipadx=0)
ttk.Button(root, text='Show', command=show_values).grid(row=2,column=0,columnspan=8)
root.mainloop()
I suppose I should have played around a bit more. It looks like the Scale widget listens to the sticky keyword in the grid manager.
w1 = ttk.Scale(root, to=7, command=scaleFunc, length=None)
w1.grid(row=1,column=0,columnspan=8,padx=(10,7),sticky='NSEW')
You can use either one of these solutions:
Solution 1: w1.grid(row = 1, column = 0, columnspan=8, sticky='ew')
Solution 2: w1 = ttk.Scale(root, to=7, command=scaleFunc, length=250)
The 1st solution is cleaner.

Python : Bokeh : make frame invisible

I am playing around with Bokeh for some time now and am really amazed how easy it is to create beautiful charts.
There is one visual thing I am not able to solve, however.
If I turn of background and borders all my charts still have some kind of border / frame. Can you turn this off as well?
E.g. If I use the following code to turn off my background, border and axis I still end up with a frame around the plot figure.
p.xaxis.visible = False
p.yaxis.visible = False
p.xgrid.visible = False
p.ygrid.visible = False
p.background_fill_color = None
p.border_fill_color = None
Here is my plot example.
Any idea how to get rid of the grey frame?
Thanks for your help!
You can remove it by setting p.outline_line_color to None.
Also by the way you can set p.axis.visible and p.grid.visible you don't need to specify the x and y axes separately

How do I change the size of a GTK container widget?

I'm getting myself thoroughly confused about how Gtk controls widget sizes inside a container such as a GtkBox. Please can someone guide me through the intricacies for this question?
I have a GtkBox containing two widgets - in the example these are just two GtkButtons.
The first widget should just fill the space available inside the GtkBox container.
The second widget I want to force always to be a physical square - thus as the square enlarges, the first widget will shrink in terms of width.
Some example code will help here:
from gi.repository import Gtk
def on_check_resize(window):
boxallocation = mainbox.get_allocation()
width = 0
height = 0
if boxallocation.height >= boxallocation.width:
width = boxallocation.height
height = width
if boxallocation.width >= boxallocation.height:
width = boxallocation.width
height = width
secondbtn_allocation = secondbtn.get_allocation()
secondbtn_allocation.width = width
secondbtn_allocation.height = height
secondbtn.set_allocation(secondbtn_allocation)
win = Gtk.Window(title="Containers Demo")
win.set_border_width(10)
win.connect("delete-event", Gtk.main_quit)
mainbox = Gtk.Box()
firstbtn = Gtk.Button(label="just fills the space")
mainbox.pack_start(firstbtn, True, True, 0)
secondbtn = Gtk.Button(label="square")
mainbox.pack_start(secondbtn, False, True, 1)
win.add(mainbox)
win.connect("check_resize", on_check_resize)
win.show_all()
initial = firstbtn.get_allocation()
initial.height = initial.width
firstbtn.set_size_request(initial.width, initial.height)
Gtk.main()
When you expand the window - the GtkBox will likewise expand. That's good. The first button similarly also expands. Good also. However, the second button never is square even though I'm using the set_allocation method for the GtkWidget.
I cannot use the set_size_request (or could I?) because when I shrink the window, the window cannot resize due to the altered minimum size of the second button.
The reason why I'm trying to figure out how containers manage spacing is that I'm looking to eventually implement something like this iTunes example:
i.e. you can see the cover is always square - but the music details will shrink or expand to depending upon the space available.
Instead of Gtk.Box, use Gtk.Grid and set the hexpand and vexpand properties on the buttons that you pack into the grid.
Also, consider using a Gtk.AspectFrame for the square button.

Categories