Skip to content

Instantly share code, notes, and snippets.

@tsu-nera
Created March 2, 2014 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tsu-nera/9304523 to your computer and use it in GitHub Desktop.
Save tsu-nera/9304523 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