-
Notifications
You must be signed in to change notification settings - Fork 1
Widget Windows
Creating widgets onto the canvas used to be a pain. Now, it's easier and takes just 1 method to do so. Using the provided methods also simplify the process greatly, making it more beginner-friendly.
- Button
- Checkbutton
-
Entry
- [Getting Values from an Entry on Click]
- Frame
- Label
- LabelFrame
- Listbox
- Menu
- PanedWindow
- RadioButton
- Scale
- Scrollbar
- Spinbox
- Text
- Toplevel
**kwargs are automatically allocated to the correct element, i.e background will be "allocated" towards the widget while "anchor" will be allocated to the window creation
Puts a button on the canvas
from typing import Tuple
from numbers import Real
from tkinter import Button
def create_button(self, x: Real, y: Real, **kwargs) -> Tuple[int, Button]from CanvasPlus import CanvasPlus
from tkinter import Tk
root = Tk()
canvas = CanvasPlus(root, width=800, height=800, background = "white")
canvas.pack()
#button that prints "Hello world!" on click
canvas.create_button(
400, 400, text = "my_button", highlightbackground = "blue", anchor = "center", command = print("Hello world!")
)
canvas.update()
canvas.mainloop()
For more on tkinter button, go to https://effbot.org/tkinterbook/button.htm
Puts a checkbutton on the canvas
from numbers import Real
from typing import Tuple
from tkinter import Checkbutton
def create_checkbutton(self, x: Real, y: Real, **kwargs) -> Tuple[int, Checkbutton]from CanvasPlus import CanvasPlus
from tkinter import Tk
root = Tk()
canvas = CanvasPlus(root, width=800, height=800, background = "white")
canvas.pack()
#checkbutton that is activated by defualt
_, checkbutton = canvas.create_checkbutton(
400, 400, anchor = "center", bg = "brown", fg = "white", text = "My Checkbutton"
)
checkbutton.toggle()
canvas.update()
canvas.mainloop()
For more on tkinter checkbutton, go to https://effbot.org/tkinterbook/checkbutton.htm
Puts an entry box on the canvas
from numbers import Real
from typing import Tuple
from tkinter import Entry
def create_entry(self, x: Real, y: Real, **kwargs) -> Tuple[int, Entry]from CanvasPlus import CanvasPlus
from tkinter import Tk, StringVar
root = Tk()
canvas = CanvasPlus(root, width=800, height=800, background = "white")
canvas.pack()
content = StringVar()
canvas.create_entry(400, 400, anchor = "center", textvariable = content, fg = "black", bg = "white")
content.set("a default value")
canvas.update()
canvas.mainloop()
Copyright (C) 2020 Luke Zhang
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the conditions at https://github.com/Luke-zhang-04/CanvasPlus/blob/master/LICENSE.