简体   繁体   English

如何更改显示tkinter Scale小部件当前值的一侧?

[英]How to change the side where the current value of the tkinter Scale widget is being displayed?

I am using a tkinter Scale widget and I have two scales next to each other. 我正在使用tkinter Scale小部件,我有两个彼此相邻的音阶。 I want the numbers on one of them to go to the other side. 我希望其中一个的数字转到另一边。

This is the code I am using: 这是我正在使用的代码:

#IMPORTS
from tkinter import *
import time

#USER INPUT
user = input("Please Enter Your Username")
time.sleep(0.4)
pass_ = imput("Please Enter Your Password")
time.sleep(0.6)              

#DEFINITIONS

#STUFF
master = Tk()

#LEFT
left = Scale(master,from_=0,to=249,length=550,width=25,tickinterval=152,sliderlength=30)
left.pack()
left.set(152)
left.grid(row=0, column=3)

#RIGHT
right = Scale(master,from_=0,to=249,length=550,width=25,tickinterval=152,sliderlength=30)
right.pack()
right.set(152)
right.grid(row=0, column=6)

#BUTTONS
send = Button(master,text="Send To Bot",command=send)
send.pack()
send.grid(row=15, column=4)

#RUN CANVAS
mainloop()

I want the right scale to have the numbers on the right side and the left scale to have the numbers on the left side (set by default). 我希望正确的比例在右侧和左侧刻度上有数字在左侧(默认设置)。

(By the way this coding isn't finished which is why the definitions aren't done.) (顺便说一下,这个编码没有完成,这就是定义没有完成的原因。)

I don't think there's a way to specify to the widget which side the number appears on. 我不认为有一种方法可以指定小部件显示在哪一侧。 However, you can customize the widget's showvalue attribute to turn off the default label, and assign an IntVar() to the scale's variable attribute to monitor the value of the slider externally, and update a Label widget that you can place anywhere as the value of the slider changes: 但是,您可以自定义窗口小部件的showvalue属性以关闭默认标签,并将IntVar()分配给缩放的variable属性以从外部监视滑块的值,并更新可以放置在任何位置的Label窗口小部件作为值滑块更改:

master = Tk()

leftValue = IntVar()  # IntVars to hold
rightValue = IntVar() # values of scales

leftScale = Scale(master, from_=0, to=249, variable=leftValue, showvalue=0)
leftScale.set(152)

rightScale = Scale(master, from_=0, to=249, variable=rightValue, showvalue=0)
rightScale.set(152)

leftLabel = Label(master, textvariable=leftValue)   # labels that will update
rightLabel = Label(master, textvariable=rightValue) # with IntVars as slider moves

leftLabel.grid(row=0, column=0)
leftScale.grid(row=0, column=1)
rightLabel.grid(row=0, column=3)
rightScale.grid(row=0, column=2)

mainloop()

Of course, the labels won't move as the slider changes, but if you really need that functionality, you could look into creating a subclass of Frame, and finding a way to change the geometry of the Label as the slider's value changes. 当然,标签不会随着滑块的变化而移动,但是如果你真的需要这个功能,你可以考虑创建一个Frame的子类,并找到一种方法来改变Label的几何形状,因为滑块的值会发生变化。

Edit: Just as a note, you shouldn't mix pack and grid in your code. 编辑:就像一个注释,你不应该在你的代码中混合包和网格。 All of those widgets should be handled by just one geometry manager. 所有这些小部件都应该只由一个几何管理器处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用tkinter Scale小部件的值连续更改图像 - How to continuously change an image using the value of a tkinter Scale widget 如何打印tkinter Scale小部件的值? - How to print the value of a tkinter Scale widget? Tkinter:如何使用 scale-widget 的值来更改 label-widget 的文本? - Tkinter: How do I use the value of a scale-widget to change the text of a label-widget? 如何从 tkinter Scale 小部件显示中删除比例值? - How to remove scale value from tkinter Scale widget display? 如何根据Python中另一个tkinter`Scale`小部件的值来控制tkinter`Scale`小部件的值? - How control the value of a tkinter `Scale` widget depending on the value of another tkinter `Scale` widget in Python? 如何在Python中为tkinter Scale小部件设置初始值? - How set the initial value for a tkinter Scale widget in Python? 如何在Python中检索tkinter ttk Scale小部件的整数值? - How to retrieve the integer value of tkinter ttk Scale widget in Python? 更改显示在 pandastable(tkinter 小部件)中的数据框 - Change dataframe displayed in pandastable (tkinter widget) 如何在Tkinter中使用Scale小部件更新matplotlib - How to update matplotlib with Scale widget in Tkinter 如何将Tkinter Scale小部件的状态设置为Disabled? - How to set the state of a tkinter Scale widget to disabled?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM