Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_scaleentry_init(self):
scale = ScaleEntry(self.window)
scale.pack()
self.window.update()
def test_scaleentry_scale(self):
scale = ScaleEntry(self.window)
scale.pack()
self.window.update()
scale.config_scale(length=100)
self.window.update()
self.assertEqual(scale.cget_scale('length'), 100)
try:
info = scale._scale.grid_info()
except TypeError:
# bug in some tkinter versions
res = str(scale.tk.call('grid', 'info', scale._scale._w)).split("-")
info = {}
for i in res:
if i:
key, val = i.strip().split()
info[key] = val
self.assertEqual(info['sticky'], 'ew')
self.assertRaises(TypeError, lambda: ScaleEntry(self.window, entryscalepad='a'))
def test_scaleentry_property(self):
scale = ScaleEntry(from_=50)
self.assertEqual(scale.value, 50)
def test_scaleentry_methods(self):
scale = ScaleEntry(self.window, scalewidth=100, entrywidth=4, from_=-10,
to=10, orient=tk.VERTICAL, compound=tk.TOP,
entryscalepad=10)
scale.pack()
self.window.update()
keys = ['borderwidth', 'padding', 'relief', 'width', 'height',
'takefocus', 'cursor', 'style', 'class', 'scalewidth', 'orient',
'entrywidth', 'from', 'to', 'compound', 'entryscalepad']
keys.sort()
self.assertEqual(scale.keys(), keys)
self.assertEqual(scale['orient'], tk.VERTICAL)
self.assertEqual(scale['scalewidth'], 100)
self.assertEqual(scale['entrywidth'], 4)
self.assertEqual(scale['from'], -10)
self.assertEqual(scale['to'], 10)
self.assertEqual(scale['compound'], tk.TOP)
self.assertEqual(scale['entryscalepad'], 10)
def test_scaleentry_entry(self):
scale = ScaleEntry(self.window, from_=0, to=50)
scale.pack()
self.window.update()
scale.config_entry(width=10)
self.window.update()
self.assertEqual(scale.cget_entry('width'), 10)
scale._entry.delete(0, tk.END)
scale._entry.insert(0, "5")
scale._on_entry(None)
self.assertEqual(scale._variable.get(), 5)
scale._entry.insert(0, "a")
scale._on_entry(None)
self.assertEqual(scale._variable.get(), 5)
scale._entry.insert(0, "")
scale._on_entry(None)
self.assertEqual(scale._variable.get(), 5)
self.assertRaises(ValueError, lambda: ScaleEntry(compound="something!"))
self.assertRaises(TypeError, lambda: ScaleEntry(self.window, entryscalepad='a'))
# -*- coding: utf-8 -*-
# Copyright (c) Juliette Monsel 2018
# For license see LICENSE
from ttkwidgets import ScaleEntry
import tkinter as tk
window = tk.Tk()
scaleentry = ScaleEntry(window, scalewidth=200, entrywidth=3, from_=0, to=20)
scaleentry.config_entry(justify='center')
scaleentry.pack()
window.mainloop()