Created
March 2, 2014 10:15
-
-
Save tsu-nera/9304523 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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