Skip to content

Instantly share code, notes, and snippets.

@dsisnero
Forked from tsu-nera/popup.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/f2eccc81985907ea21741e6477584fdd to your computer and use it in GitHub Desktop.
Save dsisnero/f2eccc81985907ea21741e6477584fdd to your computer and use it in GitHub Desktop.
エラーダイヤログ表示
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'tk'
require 'pp'
class TkWindow_Main
def initialize()
@root = TkRoot.new {
title 'Root'
resizable [0,0]
}
TkButton.new(@root,
'text' => "Check",
'command' => proc {
check_file
}
).pack
end
def check_file()
if !File.exist?("hogehoge.txt")
TkWindow_Sub.new(1)
end
end
end
class TkWindow_Sub
def initialize(error_code)
sub_window = TkToplevel.new() {
title 'Sub Window'
resizable [0,0]
grab
}
@wdg_txt = TkText.new(sub_window) {
height '5'
width '30'
}.pack('padx' => 5, 'pady' => 5)
@wdg_txt.insert('end', getMsg(error_code))
@wdg_txt.state('disabled')
TkButton.new(sub_window,
'text' => "OK",
'command' => proc {
sub_window.destroy
}
).pack('side' => 'right', 'padx' => 5)
end
def getMsg(error_code)
if error_code==1
return "file not exist"
end
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