3. click the button to draw a sine wave.
[Python]
From Tkinter import *
Import matplotlib. pyplot as plt
Import numpy as np
Def draw_sin ():
# Draw a circle of sin
T = np. arange (1,256, 1)
Y = np. sin (2 * np. pi * t/256)
Plt. plot (t, y, 'G ')
Plt. show ()
Root = Tk (className = 'drawsin ')
Label = Label (root)
Label ['text'] = 'draw sin'
Label. pack ()
Button = Button (root)
Button ['text'] = 'draw'
Button ['command'] = draw_sin
Button. pack ()
Root. mainloop ()
From Tkinter import *
Import matplotlib. pyplot as plt
Import numpy as np
Def draw_sin ():
# Draw a circle of sin
T = np. arange (1,256, 1)
Y = np. sin (2 * np. pi * t/256)
Plt. plot (t, y, 'G ')
Plt. show ()
Root = Tk (className = 'drawsin ')
Label = Label (root)
Label ['text'] = 'draw sin'
Label. pack ()
Button = Button (root)
Button ['text'] = 'draw'
Button ['command'] = draw_sin
Button. pack ()
Root. mainloop ()
Effect
Show Main Menu
Click the button to draw a picture
4. click the button to change the waveform.
[Python]
#! Usr/bin/env/python
# Coding = UTF-8
From Tkinter import *
Import matplotlib. pyplot as plt
Import numpy as np
Import sys
# Number of point
Number = 1024
# Init frequency value
Frequency = 1
# Set the recur depth
Sys. setrecursionlimit (1000000)
Def draw_sin ():
'''''Raw a circle of sin '''
# Generate the time base
T = np. arange (1, Number, 1)
# Generate the signal
Y = np. sin (2 * np. pi * frequency * t/Number)
Plt. plot (t, y)
Plt. grid (True)
Plt. text (900, 0.75, 'frequency is '+ str (Frequency ))
Plt. show ()
Def frequency_plus ():
'''''Function of add the frequency and plot the signal '''
# Notice: frequency is a global variable
Global frequency
Frequency = frequency + 1
# Clear a figure window
Plt. clf ()
Draw_sin ()
Def my_button (root, label_text, button_text, button_func ):
'''''Function of creat label and button '''
# Label details
Label = Label (root)
Label ['text'] = label_text
Label. pack ()
# Label details
Button = Button (root)
Button ['text'] = button_text
Button ['command'] = button_func
Button. pack ()
Def main ():
'''''Main function '''
Root = Tk (className = 'drawsin ')
# Draw button function
My_button (root, 'draw sin', 'click to draw', draw_sin)
# Frequency plus function
My_button (root, 'freq Plus ', 'click to Plus', frequency_plus)
Root. mainloop ()
If _ name _ = "_ main __":
Main ()
#! Usr/bin/env/python
# Coding = UTF-8
From Tkinter import *
Import matplotlib. pyplot as plt
Import numpy as np
Import sys
# Number of point
Number = 1024
# Init frequency value
Frequency = 1
# Set the recur depth
Sys. setrecursionlimit (1000000)
Def draw_sin ():
'''Raw a circle of sin '''
# Generate the time base
T = np. arange (1, Number, 1)
# Generate the signal
Y = np. sin (2 * np. pi * frequency * t/Number)
Plt. plot (t, y)
Plt. grid (True)
Plt. text (900, 0.75, 'frequency is '+ str (Frequency ))
Plt. show ()
Def frequency_plus ():
'''Function of add the frequency and plot the signal '''
# Notice: frequency is a global variable
Global frequency
Frequency = frequency + 1
# Clear a figure window
Plt. clf ()
Draw_sin ()
Def my_button (root, label_text, button_text, button_func ):
'''Function of creat label and button '''
# Label details
Label = Label (root)
Label ['text'] = label_text
Label. pack ()
# Label details
Button = Button (root)
Button ['text'] = button_text
Button ['command'] = button_func
Button. pack ()
Def main ():
'''Main function '''
Root = Tk (className = 'drawsin ')
# Draw button function
My_button (root, 'draw sin', 'click to draw', draw_sin)
# Frequency plus function
My_button (root, 'freq Plus ', 'click to Plus', frequency_plus)
Root. mainloop ()
If _ name _ = "_ main __":
Main ()
Effect
Show Main Menu
Click the button to change the frequency