Teknologi 3D pada Halaman WEB
Rabu, 15 Oktober 2025
Minggu, 12 Oktober 2025
Jumat, 10 Oktober 2025
WXPYTHON - import AnimationCtrl, Animation - Menampilkan File Animasi Gif
import wx
from wx.adv import AnimationCtrl, Animation
app=wx.App()
frame = wx.Frame(None, -1, title='2', pos=(0, 0), size=(200, 200))
app.SetTopWindow(frame)
anim = Animation(r'C:\Users\Acer\Pictures\animt.gif')
anim_ctrl = AnimationCtrl(frame, -1, anim)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(anim_ctrl)
frame.SetSizerAndFit(sizer)
frame.Show()
anim_ctrl.Play()
app.MainLoop()
PYTHON - TKINTER - NUMPY
import tkinter
import numpy as np
# Implement the default Matplotlib key bindings.
from matplotlib.backend_bases import key_press_handler
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg,
NavigationToolbar2Tk)
from matplotlib.figure import Figure
root = tkinter.Tk()
root.wm_title("Embedded in Tk")
fig = Figure(figsize=(5, 4), dpi=100)
t = np.arange(0, 3, .01)
ax = fig.add_subplot()
line, = ax.plot(t, 2 * np.sin(2 * np.pi * t))
ax.set_xlabel("time [s]")
ax.set_ylabel("f(t)")
canvas = FigureCanvasTkAgg(fig, master=root) # A tk.DrawingArea.
canvas.draw()
# pack_toolbar=False will make it easier to use a layout manager later on.
toolbar = NavigationToolbar2Tk(canvas, root, pack_toolbar=False)
toolbar.update()
canvas.mpl_connect(
"key_press_event", lambda event: print(f"you pressed {event.key}"))
canvas.mpl_connect("key_press_event", key_press_handler)
button_quit = tkinter.Button(master=root, text="Quit", command=root.destroy)
def update_frequency(new_val):
# retrieve frequency
f = float(new_val)
# update data
y = 2 * np.sin(2 * np.pi * f * t)
line.set_data(t, y)
# required to update canvas and attached toolbar!
canvas.draw()
slider_update = tkinter.Scale(root, from_=1, to=5, orient=tkinter.HORIZONTAL,
command=update_frequency, label="Frequency [Hz]")
# Packing order is important. Widgets are processed sequentially and if there
# is no space left, because the window is too small, they are not displayed.
# The canvas is rather flexible in its size, so we pack it last which makes
# sure the UI controls are displayed as long as possible.
button_quit.pack(side=tkinter.BOTTOM)
slider_update.pack(side=tkinter.BOTTOM)
toolbar.pack(side=tkinter.BOTTOM, fill=tkinter.X)
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=True)
tkinter.mainloop()
WXPYTHON - BoxSizer
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, title):
super(MyFrame, self).__init__(parent, title=title, size=(300, 200))
panel = wx.Panel(self)
vbox = wx.BoxSizer(wx.VERTICAL)
# Add a text control
text_ctrl = wx.TextCtrl(panel)
vbox.Add(text_ctrl, proportion=0, flag=wx.EXPAND | wx.ALL, border=5)
# Add some buttons
hbox = wx.BoxSizer(wx.HORIZONTAL)
btn1 = wx.Button(panel, label='Button 1')
btn2 = wx.Button(panel, label='Button 2')
hbox.Add(btn1, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
hbox.Add(btn2, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
vbox.Add(hbox, proportion=1, flag=wx.EXPAND)
panel.SetSizer(vbox)
self.Centre()
self.Show()
app = wx.App()
frame = MyFrame(None, "Geometry Example")
app.MainLoop()
WXPYTHON - MessageBox
import wx
class MyFrame(wx.Frame):
def __init__(self):
super().__init__(parent=None, title='My wxPython App with Sizers')
panel = wx.Panel(self)
# Create a vertical box sizer
vbox = wx.BoxSizer(wx.VERTICAL)
# Add a StaticText
text_label = wx.StaticText(panel, label="Enter your name:")
vbox.Add(text_label, 0, wx.ALL | wx.EXPAND, 5) # Add with padding and expansion
# Add a TextCtrl
self.name_input = wx.TextCtrl(panel)
vbox.Add(self.name_input, 0, wx.ALL | wx.EXPAND, 5)
# Add a Button
greet_button = wx.Button(panel, label="Greet")
greet_button.Bind(wx.EVT_BUTTON, self.on_greet)
vbox.Add(greet_button, 0, wx.ALL | wx.CENTER, 5)
panel.SetSizer(vbox) # Set the sizer for the panel
self.Layout() # Re-calculate layout
self.Show()
def on_greet(self, event):
name = self.name_input.GetValue()
if name:
wx.MessageBox(f"Hello, {name}!", "Greeting", wx.OK | wx.ICON_INFORMATION)
else:
wx.MessageBox("Please enter your name.", "Warning", wx.OK | wx.ICON_WARNING)
if __name__ == '__main__':
app = wx.App()
frame = MyFrame()
app.MainLoop()