-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathplot_window_raw_tk.rb
More file actions
26 lines (23 loc) · 904 Bytes
/
plot_window_raw_tk.rb
File metadata and controls
26 lines (23 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Minimal method to show a window with the figure using raw Tk
#
def plot_window(root = false)
figure = Rubyplot::Artist::Figure.new(height: 20, width: 20)
window = root ?
TkRoot.new { title "Plot Demo" } :
TkToplevel.new { title "Plot Demo" }
content = Tk::Tile::Frame.new(window).grid(sticky: 'nsew', column: 1, row: 1)
TkGrid.columnconfigure window, 1, weight: 1
TkGrid.rowconfigure window, 1, weight: 1
canvas = TkCanvas.new(content) { width 600; height 600 }
canvas.grid sticky: 'nwes', column: 1, row: 1
refresh_button = Tk::Tile::Button.new(content) do
text "Refresh!"
command { Tk.update; figure.show(canvas) }
end.grid(column: 1, row: 2, sticky: 'es')
TkGrid.columnconfigure content, 1, weight: 1
TkGrid.rowconfigure content, 1, weight: 1
TkGrid.rowconfigure content, 2, weight: 0
yield figure
Tk.update
figure.show(canvas)
end