Guest User

Untitled

a guest
Feb 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.75 KB | None | 0 0
  1. require "rubygems"
  2. gem "rubyscript2exe"
  3. require "rubyscript2exe"
  4. #bindet Tk in Rubyscript2exe ein
  5. RUBYSCRIPT2EXE.tk = true
  6. #ohne Konsole
  7. RUBYSCRIPT2EXE.rubyw = true
  8.  
  9. require 'tk'
  10.  
  11. class Mama
  12.  
  13. #TK Fenster wird gestartet
  14. def run
  15. @window.mainloop
  16. end
  17.  
  18.  
  19. def initialize
  20. #Erstellt das Hauptfenster
  21. @window = TkRoot.new(:title => 'Lebensmittel-Verwaltung', 'height' => 674, 'width' => 1000) do
  22. root.geometry('+100+100')
  23. end
  24.  
  25.  
  26. bild_label()
  27. lebensmittelverwatltung_label()
  28. button_add()
  29. button_deleate()
  30. liste()
  31. button_end()
  32. text()
  33. end
  34.  
  35. #Label mit Lebensmittelbild
  36. def bild_label
  37. image1 = TkPhotoImage.new { file "bilder/Lebensmittel.gif" }
  38. TkLabel.new('height' => 674, 'width' => 1000) do
  39. place 'x' => 0, 'y' => 0
  40. image image1
  41. end
  42. end
  43.  
  44. #Label mit der Aufschgrift: Mamas Lebensmittel Verwaltung
  45. def lebensmittelverwatltung_label
  46. TkLabel.new('height' => 1, 'width' => 26) do
  47. text 'Mamas Lebensmittel-Verwaltung'
  48. place 'x' => 145, 'y' => 0
  49. font TkFont.new('Comic 35 bold')
  50. relief 'raised'
  51. foreground 'Lime Green'
  52. background 'Orange Red'
  53. end
  54. end
  55.  
  56. #Button zum öffnen des imports
  57. def button_add
  58. image1 = TkPhotoImage.new { file "bilder/add.gif" }
  59. a = TkButton.new('height' => 94, 'width' => 94) do
  60. place 'x' => 279, 'y' => 480
  61. image image1
  62. cursor "hand2"
  63. relief 'groove'
  64. end
  65. a.bind('ButtonRelease-1') do
  66. delat_lvl()
  67. @win1.state = 'withdrawn'
  68. add_lvl()
  69. button_end1('Green Yellow')
  70. end
  71. end
  72.  
  73. #Button um etwas herauszunehmen
  74. def button_deleate
  75. image1 = TkPhotoImage.new { file "bilder/delate.gif" }
  76. a = TkButton.new('height' => 94, 'width' => 94) do
  77. place 'x' => 741, 'y' => 480
  78. image image1
  79. cursor "hand2"
  80. relief 'groove'
  81. end
  82. a.bind('ButtonRelease-1') do
  83. add_lvl()
  84. @win.state = 'withdrawn'
  85. delat_lvl()
  86. button_end1('blue')
  87. end
  88. end
  89.  
  90. #Button um Programm zu beenden
  91. def button_end
  92. image1 = TkPhotoImage.new { file "bilder/exit.gif" }
  93. bt = TkButton.new('height' => 30, 'width' => 30) do
  94. place 'x' => 965, 'y' => 1
  95. image image1
  96. cursor "hand2"
  97. relief 'flat'
  98. end
  99. bt.bind('ButtonRelease-1') do
  100. @window.destroy
  101. end
  102. end
  103.  
  104. #2. End Button um Konfigurationen zu beenden
  105. def button_end1(lol)
  106. image1 = TkPhotoImage.new { file "bilder/exit2.gif" }
  107. image2 = TkPhotoImage.new { file "bilder/lb.gif" }
  108. @bt = TkButton.new('height' => 20, 'width' => 244) do
  109. place 'x' => 10, 'y' => 640
  110. image image1
  111. cursor "hand2"
  112. relief 'flat'
  113. background "#{lol}"
  114. end
  115. @bt.bind('1') do
  116. delat_lvl()
  117. add_lvl()
  118. @win.state = 'withdrawn'
  119. @win1.state = 'withdrawn'
  120. @bt.configure('image', image2)
  121. end
  122. end
  123.  
  124. #Liste mit Inhalt
  125. def liste
  126. @lis = TkListbox.new('height' => 14, 'width' => 49) do
  127. selectmode 'single'
  128. place 'x' => 279, 'y' => 90
  129. font TkFont.new('Comic 15 bold')
  130. background 'Forest green'
  131. end
  132.  
  133.  
  134. scrol = TkScrollbar.new do
  135. orient 'vertical'
  136. command { |*args| lis.yview *args }
  137. place 'x' => 824, 'y' => 90, 'height' => 357
  138. end
  139. scrol.set(0, 0)
  140.  
  141. @lis.yscrollcommand do |first, last|
  142. scrol.set(first, last)
  143. end
  144. end
  145.  
  146. #Topp lvl add
  147. def add_lvl
  148. begin
  149. @win.destroy
  150. rescue
  151. end
  152. @win = TkToplevel.new(:title => 'hinzufuegen', 'height' => 560, 'width' => 250) do
  153. relief 'ridge'
  154. geometry('+114+206')
  155. background 'Green Yellow'
  156. end
  157. @win.overrideredirect(true)
  158.  
  159.  
  160. @e1 = TkEntry.new(@win) do
  161. place 'x' => 50, 'y' => 130
  162. end
  163. @e4 = TkEntry.new(@win) do
  164. place 'x' => 50, 'y' => 200
  165. end
  166.  
  167. TkLabel.new(@win) do
  168. place 'x' => 50, 'y' => 15
  169. text 'Import'
  170. background 'blue'
  171. relief 'groove'
  172. font TkFont.new('Comic 30 bold')
  173. foreground 'Green Yellow'
  174. end
  175.  
  176. TkLabel.new(@win) do
  177. place 'x' => 50, 'y' => 102
  178. text 'Lebensmittel:'
  179. background 'Brown'
  180. relief 'groove'
  181. font TkFont.new('Comic 10 bold')
  182. foreground 'yellow'
  183. end
  184.  
  185. TkLabel.new(@win) do
  186. place 'x' => 50, 'y' => 174
  187. text 'Anzahl:'
  188. background 'Brown'
  189. relief 'groove'
  190. font TkFont.new('Comic 10 bold')
  191. foreground 'yellow'
  192. end
  193.  
  194. image1 = TkPhotoImage.new { file "bilder/ok.gif" }
  195. @bt12 = TkButton.new(@win) do
  196. place 'x' => 60, 'y' => 300
  197. image image1
  198. end
  199. @bt12.bind('ButtonRelease-1') do
  200. @leb1 = @e1.value
  201. @leb77 = @e4.value.to_i
  202.  
  203. if File.exist?("data/#{@leb1}.txt")
  204. File.open("data/#{@leb1}.txt") do |file|
  205. file.each do |line|
  206. @leb222 = line
  207. end
  208. file.close
  209. end
  210. File.open("data/#{@leb1}.txt", "w+") do |file|
  211. lol = @leb222.to_i
  212. ac = @leb77
  213. @leb100 = "#{lol + ac}"
  214. file.puts "#{@leb100}"
  215. file.close
  216. end
  217. else
  218. File.open("data/#{@leb1}.txt", "w+") do |file|
  219. lol = @leb222.to_i
  220. ac = @leb77
  221. @leb100 = "#{lol + ac}"
  222. file.puts "#{@leb100}"
  223. file.close
  224. end
  225. end
  226. end
  227. end
  228.  
  229.  
  230. # Top lvl deleat
  231. def delat_lvl
  232. begin
  233. @win1.destroy
  234. rescue
  235. end
  236. @win1 = TkToplevel.new(:title => 'hinzufuegen', 'height' => 560, 'width' => 250) do
  237. relief 'ridge'
  238. geometry('+114+206')
  239. background 'Blue'
  240. end
  241. @win1.overrideredirect(true)
  242.  
  243. @e2 = TkEntry.new(@win1) do
  244. place 'x' => 50, 'y' => 130
  245. end
  246. @e3 = TkEntry.new(@win1) do
  247. place 'x' => 50, 'y' => 200
  248. end
  249.  
  250. #Export
  251. TkLabel.new(@win1) do
  252. place 'x' => 50, 'y' => 15
  253. text 'Export'
  254. background 'Green Yellow'
  255. relief 'groove'
  256. font TkFont.new('Comic 30 bold')
  257. foreground 'blue'
  258. end
  259.  
  260. TkLabel.new(@win1) do
  261. place 'x' => 50, 'y' => 102
  262. text 'Lebensmittel:'
  263. background 'Brown'
  264. relief 'groove'
  265. font TkFont.new('Comic 10 bold')
  266. foreground 'yellow'
  267. end
  268.  
  269. TkLabel.new(@win1) do
  270. place 'x' => 50, 'y' => 174
  271. text 'Anzahl:'
  272. background 'Brown'
  273. relief 'groove'
  274. font TkFont.new('Comic 10 bold')
  275. foreground 'yellow'
  276. end
  277. image1 = TkPhotoImage.new { file "bilder/okk.gif" }
  278. @bt13 = TkButton.new(@win1) do
  279. place 'x' => 60, 'y' => 300
  280. image image1
  281. end
  282.  
  283. @bt13.bind('ButtonRelease-1') do
  284. @leb6 = @e2.value
  285. @leb7 = @e3.value.to_i
  286.  
  287. File.open("data/#{@leb6}.txt") do |file|
  288. file.each do |line|
  289. @leb22 = line
  290. end
  291. file.close
  292. end
  293. if File.exist?("data/#{@leb6}.txt")
  294. File.open("data/#{@leb6}.txt", "w") do |file|
  295. lol = @leb22.to_i
  296. ac = @leb7
  297. @leb10 = "#{lol - ac}"
  298. file.puts "#{@leb10}"
  299. file.close
  300. end
  301. else
  302. msgBox = Tk.messageBox(
  303. 'type' => "ok",
  304. 'icon' => "info",
  305. 'title' => "Nicht Foraethig",
  306. 'message' => "Dieses Produkt ist leider nicht im Lager"
  307. )
  308.  
  309. end
  310. end
  311.  
  312. end
  313. def text
  314. File.open("data/.") do |file|
  315. @jojo = file.to_s
  316. end
  317. File.open("complet.txt", "w+") do |file|
  318. file.puts "#{@jojo}"
  319. end
  320. end
  321.  
  322. end
  323.  
  324.  
  325. los = Mama.new
  326. los.run
Add Comment
Please, Sign In to add comment