Skip to content

Instantly share code, notes, and snippets.

@dsisnero
Forked from tsu-nera/tkwindow_observer.rb
Created April 10, 2018 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsisnero/20a64c235840d0770fe256ce740c66c7 to your computer and use it in GitHub Desktop.
Save dsisnero/20a64c235840d0770fe256ce740c66c7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'tk'
require 'observer'
class TkWindow_Main
def initialize()
@root = TkRoot.new {
title 'Root'
resizable [0,0]
}
@wdg_txt = TkText.new(@root).pack
@wdg_txt.insert('end', "Editしてください")
@wdg_txt.state 'disabled'
TkButton.new(@root,
'text' => "Edit",
'command' => proc {
TkWindow_Sub.new(self)
}
).pack
end
def update(text)
@wdg_txt.state 'normal'
@wdg_txt.delete('1.0', 'end')
@wdg_txt.insert('end', text)
@wdg_txt.state 'disabled'
end
end
class TkWindow_Sub
include Observable
def initialize(parent=nil)
@parent = parent
add_observer(@parent)
sub_window = TkToplevel.new() {
title 'Sub Window'
resizable [0,0]
}
TkButton.new(sub_window,
'text' => "Finish",
'command' => proc {
changed
notify_observers('Bye')
sub_window.destroy
}
).pack
end
end
if $0 == __FILE__
TkWindow_Main.new()
Tk.mainloop
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment